【发布时间】:2014-01-01 14:47:12
【问题描述】:
我制作了一个非常简单的 Spring MVC 应用程序来学习 AOP,但每次我尝试导航任何应用程序页面时,我都会收到(未找到映射)错误如下:
No mapping found for HTTP request with URI [/TestAOP/page1.htm] in DispatcherServlet with name 'appServlet'
我已经检查了 web.xml、servlet-context.xml、控制器代码,但没有发现任何错误。因此,如果有人可以查看我的 web.xml、servlet-context.xml 和控制器的内容并让我知道我在这里缺少什么以及如何克服这个错误,我将非常感激。感谢您的宝贵时间
-
Web.xml
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <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> servlet-context.xml
<annotation-driven /> <context:component-scan base-package="com.sampledomain.app.controller" /> <aop:aspectj-autoproxy/> <resources mapping="/resources/**" location="/resources/" /> <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>
-
控制器
@Controller public class HomeController { @RequestMapping(value = "/page1", method = RequestMethod.GET) public String firstPage(HttpServletRequest request,Locale locale, Model model) { Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate ); return "page01"; } } 根上下文.xml 主要是空的
注意:page01.jsp 在 /WEB-INF/views/ 文件夹下
【问题讨论】:
标签: java spring jsp spring-mvc