“/showform”不会重定向到showform.jsp页面,但“showform”会这样做

yuvru6vn  于 2021-07-13  发布在  Java
关注(0)|答案(1)|浏览(273)

索引.jsp

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title> Home Page|Spring MVC </title>
  5. </head>
  6. <body>
  7. <h2>Welcome to spring mvc</h2>
  8. <a href = "/showForm">Form</a>
  9. </body>
  10. </html>

下面是我的控制器代码

  1. @RequestMapping("/showForm")
  2. public String showForm() {
  3. return "showForm.jsp";
  4. }

下面是我用来呈现showform.jsp页面的jsp代码,问题是每当我使用/showform时它给出404,当我使用showform时它呈现showform.jsp页面。

0x6upsns

0x6upsns1#

您只需返回 .jsp 页,并且您还必须使用uri附加请求的上下文路径。
修改为:
索引.jsp

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title> Home Page|Spring MVC </title>
  5. </head>
  6. <body>
  7. <h2>Welcome to spring mvc</h2>
  8. <a href = "${pageContext.request.contextPath}/showForm">Form</a>
  9. </body>
  10. </html>

控制器:

  1. @RequestMapping("/showForm")
  2. public String showForm() {
  3. return "showForm";
  4. }

应该有用。

展开查看全部

相关问题