我使用Spring Tool Suite在eclipse中開發一個簡單的Spring 3。但是當我運行時,「HTTP狀態404所請求的資源(/ hxj /)不可用」是返回。Spring 3 HTTP狀態404
在Eclipse的控制檯:沒有錯誤,但有些信息看起來奇怪:
Jun 29, 2013 7:50:47 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(H:\My Documents\eclipse\.metadata\.plugins\org.eclipse.wst.server.core
\tmp1\wtpwebapps\Spring\WEB-INF\lib\jsp-api-2.1.jar) - jar not loaded.
Jun 29, 2013 7:50:47 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(H:\My Documents\eclipse\.metadata\.plugins\org.eclipse.wst.server.core
\tmp1\wtpwebapps\Spring\WEB-INF\lib\servlet-api-2.5.jar) - jar not loaded.
以下是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listene-class>
</listener>
<!-- Processes application requests -->
<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>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
</web-app>
和Java類的主要部分:HomeController的的.java
package com.hxj.hxj;
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat
= DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate);
return "home";
}
}
在servlet-context.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org
/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans
/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema
/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<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>
<context:component-scan base-package="com.hxj.hxj" />
</beans:beans>
我不知道爲什麼它不起作用,因爲它是一個spring springte項目的spring MVC項目。任何人都可以幫我解決這個問題嗎?
非常感謝! 夏娃
編輯: 此外,爲什麼網址是:本地主機:8080/HXJ/ 代替:本地主機:8080/HXJ /回到Home.jsp(或/home.do)?
感謝
嘗試使,在web.xml:' appServlet servlet的名稱> /* URL模式> servlet-mapping>而不是'* .do'。 –
acdcjunior
我改變了它,但仍然收到錯誤警告:WARN:org.springframework.web.servlet.PageNotFound - 在名爲'appServlet'的DispatcherServlet中找不到具有URI [/ hxj /]的HTTP請求的映射。但我已經在web.xml中定義了appServlet。任何消化?謝謝@acdcjunior – Eve