我有以下控制器...
@Controller
@RequestMapping(value = "/userManagement")
public class UserManagementController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public Object home(Locale locale, Model model) {
logger.info("User management view controller loaded...");
return "userManagement";
}
@RequestMapping(value = "/createUserView", method = RequestMethod.GET)
public Object createUser(Locale locale, Model model) {
logger.info("create controller loaded...");
return "createUser";
}
我的 servlet-context 设置了以下值...
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
现在如果我去http://localhost:8080/myapp/userManagement
然后我得到视图 userManagement.jsp 这正是我想要的......
但是如果我去http://localhost:8080/myapp/userManagement/createUserView
我会得到一个 404 错误。
NetworkError: 404 Not Found - http://localhost:8080/myapp/userManagement/createUserView"
我没有看到为什么会发生这种情况,因为我已经将 requestMapping 设置为与上面完全相同,并且在 /WEB-INF/views 我有一个 createUser.jsp 和 userManagement.jsp
关于提供来自 spring mvc 的观点,我做错了什么吗?
谢谢,
编辑:web.xml 添加在下面...
<?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/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml
/WEB-INF/spring/security-app-context.xml
/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
编辑2:
此外,如果我直接转到浏览器中的地址而不是使用 Ajax(转到 myapp/userManagement/createUserView,我会收到错误消息...
HTTP 状态 404 - /myapp/WEB-INF/views/userManagement/createUserView.jsp 所以它似乎正在查看一个太高的目录(尽管文件名也是错误的)。
编辑3。
好的,即使我执行以下操作似乎也是如此..
@Controller
@RequestMapping(value = "/userManagement")
public class UserManagementController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public Object home(Locale locale, Model model) {
logger.info("User management view controller loaded...");
return "createUser";
}
我仍然看到 userManagement.jsp 页面,所以看起来这个返回没有正确触发,但我不知道为什么。记录器详细信息仍然会被触发到控制台,因此它实际上已经到达那里,只是 springmvc 返回 JSP 的方式有些奇怪。