配置
1、将pom.xml中 packaging 修改为: <packaging>war</packaging>
2、指向自定的web.xml
Project Structure ——》Modules——》项目的Web——》Deployment Descriptors 都指向web.xml
Project Structure ——》Modules——》项目的Web——》Web Resource Directions 资源起始点 比如index.html在webapp下就定位到webapp下
3、web.xml applicationContext内容可以为空
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/config/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/springmvc-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!--
第一种:*.action访问以.action结尾由DispatcherServlet进行解析
第二种:/.所有访问的地址都由DispatcherServlet解析,对于静态文件的解析需要配置不让DispatcherServlet进行解析
使用此种方法可以实现Restful风格的url
第三种:/*这样配置不对,使用这种配置,最终要转发到一个jsp页面时,仍然会由DispatcherServlet解析jsp,
不能根据jsp页面找到handler,会报错
-->
<url-pattern>*.action</url-pattern>
</servlet-mapping>
4、扫描注解
<context:component-scan base-package="com.zhang.scyellow.remote">
</context:component-scan>
5、@ResponseBody 要加 不然404
@Controller
public class TestCtrl {
@RequestMapping(value="/run.action")
@ResponseBody
public String run(){
return "a";
}
}
知识
1、路径默认为Web Resource Directions 也就是idea蓝点的位置