我爲index.htm獲取404。您可以看到index.htm已在服務器中註冊。404在Spring MVC中爲index.htm返回
Server日誌
[0m[0m10:00:57,643 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (ServerService Thread Pool -- 201) Mapped URL path [/index.htm] onto handler 'indexController'
[0m[0m10:00:57,644 INFO [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping] (ServerService Thread Pool -- 201) Root mapping to handler 'indexController'
...
[0m[0m10:07:31,827 INFO [stdout] (http-/0.0.0.0:8080-1) Error message=404 returned for /EAFUIWeb/index.htm with message Not Found : [Fri Sep 26 10:07:31 ICT 2014]Not Found
控制器
@Controller
public class IndexController {
@RequestMapping(value={"/index.htm","/"}, method = RequestMethod.GET)
public ModelAndView initGET(HttpServletRequest request, HttpServletResponse response) throws Exception {
...
}
@RequestMapping(value={"/index.htm","/"}, method=RequestMethod.POST)
public ModelAndView loadEntity(HttpServletRequest request, HttpServletResponse response) throws Exception {
..
}
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
...
</web-app>
的index.jsp
<c:redirect url="/index.htm" />
的applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
</beans>
調度-servlet.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:sec="http://www.springframework.org/schema/security" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<sec:global-method-security
pre-post-annotations="enabled" proxy-target-class="true" />
<mvc:annotation-driven />
<mvc:resources mapping="/config/**" location="/config/" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/tmpls/**" location="/tmpls/" />
<mvc:resources mapping="/media/**"
location="file:${user.home}/uploads/avatar/" />
<context:component-scan base-package="com.bara.j2ee.pattern.control.spring,com.master.util" />
<mvc:default-servlet-handler/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
<context:property-placeholder location="classpath:ad.properties"
ignore-unresolvable="true" />
是否有y配置問題?如何修復404 for index.htm
你的春天背景在哪裏? – Desorder 2014-09-26 03:22:26
爲什麼要進入「0.0.0.0:8080」? – 2014-09-26 03:22:34
我在上面添加了spring上下文文件。 @Desorder – 2014-09-26 03:27:42