我试图在Spring MVC上开始开发,这只是一个小项目,但是我可以在Tomcat 7上部署我的项目,但是我无权访问。
当我尝试使用此URL进行访问时:
xxxx:8080/test/index
xxxx:8080/test/
xxxx:8080/test/home.do
xxxx:8080/test/welcome
我有一个错误页面HTTP 404。
我不明白为什么,因为我完全按照惯例来创建这个项目。
这是我的web.xml
<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">
<display-name>Spring CXF Servlet Mocks Integration Spring</display-name>
<servlet>
<servlet-name>court</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>court</servlet-name>
<url-pattern>*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
这是我的mvc-dispatcher-servlet.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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="com.soltani.slim" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
这是我的控制器:com.soltani.slim包;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class WelcomeController {
@RequestMapping(value = "/welcome", method = RequestMethod.GET)
public String helloWorld() {
return "welcome";
}
}
我创建了一个具有以下内容的jsp文件:
我将此文件放在以下位置:/WEB-INF/jsp/welcome.jsp
错误日志是:
No mapping found for HTTP request with URI [/test/] in DispatcherServlet with name 'Welcome'
mars 26, 2014 10:57:39 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
Avertissement: No mapping found for HTTP request with URI [/test/home.html] in DispatcherServlet with name 'Welcome'
mars 26, 2014 10:57:44 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
Avertissement: No mapping found for HTTP request with URI [/test/index] in DispatcherServlet with name 'Welcome'
mars 26, 2014 10:58:02 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
Avertissement: No mapping found for HTTP request with URI [/test/index] in DispatcherServlet with name 'Welcome'
我没有发现错误,也不知道为什么会有这个错误。无论如何,我只是使用Spring工具套件创建了一个Web项目。即使这几乎与我的项目相同,但我的项目仍进行了编译,部署和良好的工作:)
谢谢您的帮助。
最好的祝福。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句