【发布时间】:2012-07-10 20:16:36
【问题描述】:
我有以下控制器...
@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 因此它似乎正在查看一个过高的目录(尽管文件名也错误)。
EDIT3.
好的,即使我执行以下操作似乎也是如此..
@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 的方式有些奇怪。
【问题讨论】:
-
能否请您粘贴您的应用程序日志文件 - 应该有一些映射异常
-
对不起,编辑了评估的东西,只是让它更通用一点。我的控制台中没有出现异常,上面的错误只是来自 Firebug,你想要哪个应用程序日志?
-
您的网址有些有趣。看起来您的 web.xml 中可能有一个映射到 /userManagement 的调度程序 servlet?
标签: java spring spring-mvc