1. web.xml 配置如下:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MyTest</display-name>
<!-- 配置spring MVC的dispatcherServlet -->
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>com.voyage.init.MainDispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring\*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
2. 程序代码如下:
@Controller
public class MainController {
@RequestMapping(value = "survey.do")
public void doSomething(HttpServletRequest request,
HttpServletResponse response) throws IOException {
response.getWriter().println("woyun ..........ddddddddd");
}
}
3. 在windows下面 访问 http://localhost:8080/MyTest/survey.do 返回代码里面写的字符串,没有问题
4. 讲项目打war包,放到远程的linux托管主机上, 访问http://114.x.x.x:8080/MyTest/survey.do 返回404.
查看tomct日志,spring mvc 报错说 这个can not find request mapping for url xxxxxxxxxxx, 很奇怪,为啥windows下可以找到,linux下就报错呢?
------解决方案--------------------
由于window系统和linux系统的文件路径是有区别的,tomcat在linux启动时是无法识别你xml中
<param-value>classpath*:spring\*.xml</param-value>配置的路径的,将\修正为/即可