遇到这样的问题。
Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
web.xml
这是我的..\MTSM\src\main\webapp\WEB-INF\web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/ActionAdet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/ActionSure</url-pattern>
</servlet-mapping>
</web-app>
mvc-dispacher-servlet.xml
这是我的..\MTSM\src\main\webapp\WEB-INF\mvc-dispacher-servlet.xml
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="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">
<context:component-scan base-package="com.springapp.mvc"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
hello.jsp
这是我的..\MTSM\src\main\webapp\WEB-INF\pages\hello.jsp
$.get('ActionAdet', {opername: 'services'}, function (responseJson) { } ) ;..
hello.HelloController.java
这是我的..\MTSM\src\main\java\com\springapp\mvc\HelloController.java
@Controller
@RequestMapping("/")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world!");
return "ss";
}
}
ActionAdet.java
这是我的..\MTSM\src\main\java\com\springapp\mvc\ActionAdet.java
@Controller
@RequestMapping("/ActionAdet")
public class ActionAdet extends HttpServlet { } etc..
我无法在此网址中查看我的项目:localhost:7001/MTSM/
也不在localhost:7001/MTSM/hello.jsp
它在2天前工作了。我想我已经删除了web.xml
中的内容,但我不记得了
你知道什么问题吗?
我在这里上传了我的项目:[Dropbox - MTSM_20140112.zip] [3]
感谢。
答案 0 :(得分:1)
根据你在pastie中提供的日志(错误:你应该提供相关部分作为编辑),spring试图加载WEB-INF/pages/ss.jsp
而不是找到它。我的意思是:
HelloController
printWelcome
将ss
作为字符串mvc-dispacher-servlet.xml
,InternalResourceViewResolver
寻找WEB-INF/pages/ss.jsp
(正常,直到此处)您应该尝试在控制器返回的视图名称和实际的jsp文件之间保持一致:
@RequestMapping("/")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Hello world!");
return "hello";
}
}
应转发查看WEB-INF/pages/hello.jsp
(根据您的项目图像存在)