Java 找不到URI为的HTTP请求的映射 列表项
我在添加第二个控制器时出现此异常。 我有一个控制器已经和网页工作良好 但现在我添加了第二个控制器,并收到了他的错误警告:org.springframework.web.servlet.PageNotFound-在名为“spring”的DispatcherServlet中找不到URI为[/civilforsvaret-webbapp2/index.html]的HTTP请求的映射 我不明白的是为什么一个页面显示而另一个页面不显示 以下是DispatcherServlet:Java 找不到URI为的HTTP请求的映射 列表项,java,spring,spring-mvc,Java,Spring,Spring Mvc,我在添加第二个控制器时出现此异常。 我有一个控制器已经和网页工作良好 但现在我添加了第二个控制器,并收到了他的错误警告:org.springframework.web.servlet.PageNotFound-在名为“spring”的DispatcherServlet中找不到URI为[/civilforsvaret-webbapp2/index.html]的HTTP请求的映射 我不明白的是为什么一个页面显示而另一个页面不显示 以下是DispatcherServlet: <?xml vers
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>civilforsvaret-webbapp2</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
您可以为控制器设置路径的公共部分,然后为控制器内的每个方法使用特定路径:
@Controller
@RequestMapping("")
public class LoginController {
@RequestMapping(value="index.html", method = RequestMethod.GET)
public String method(Map model) {
...
}
@RequestMapping(value="login.html")
public String method2(Map model) {
...
}
}
当您遇到此错误时,意味着您的uri不匹配。 因此,您的.jsp页面或控制器中的url错误 因此,要消除这种情况,请确保您的
@RequestMapping()或返回语句中的与您在.jsp页面中调用的url匹配
Controller
@RequestMapping("/login.html")
public class LoginController {
@RequestMapping(method = RequestMethod.GET)
public String showForm(Map model) {
LoginForm loginForm = new LoginForm();
model.put("loginForm", loginForm);
return "loginform";
}
@Controller
@RequestMapping("")
public class LoginController {
@RequestMapping(value="index.html", method = RequestMethod.GET)
public String method(Map model) {
...
}
@RequestMapping(value="login.html")
public String method2(Map model) {
...
}
}