paip.spring3 mvc servlet的配置以及使用最佳实践

来源:互联网 发布:linux自检 编辑:程序博客网 时间:2024/05/22 11:36

paip.spring3 mvc servlet的配置以及使用最佳实践

 

1. Web.xml 1

2. springMVC.xml 2

1. mvcAction .mvcAction 2

2. Resin4 发动跟踪mvc maping 3

3. No mapping found for HTTP request with URI 3

 

 

 

1.Web.xml

 <servlet>     

     <servlet-name>spring</servlet-name>     

     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>     

    <init-param>  

        <param-name>contextConfigLocation</param-name>  

        <param-value>/WEB-INF/springMVC.xml</param-value>  

    </init-param>     

     <load-on-startup>1</load-on-startup>     

 </servlet>     

 <servlet-mapping>     

     <servlet-name>spring</servlet-name>  <!-- 这里在配成spring,下边也要写一个名为spring-servlet.xml的文件,主要用来配置它的controller -->   

     <url-pattern>*.json</url-pattern>     

 </servlet-mapping>  

 

Xml的位置可以放得个多个地张儿..不过mvc还是放得个web-inf哈面儿好,不用铜布xml...减少部署的问题..

多个文件/WEB-INF/xxx/*.xml

classpath*:/springMVC.xml

 

 

作者Attilax 艾龙,  EMAIL:1466519819@qq.com 
来源:老哇的爪子 Attilax 
地址:http://blog.csdn.net/attilax

2.springMVC.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:context="http://www.springframework.org/schema/context"   

    xmlns:aop="http://www.springframework.org/schema/aop" 

    xmlns:tx="http://www.springframework.org/schema/tx"   

    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xmlns:p="http://www.springframework.org/schema/p"

    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      

           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd      

           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

     <mvc:default-servlet-handler/>       

<mvc:annotation-driven />

<context:annotation-config />

<context:component-scan base-package="comapi.**,com.im"/>

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />  

</beans>

 

1.mvcAction .mvcAction 

@Controller  

 @RequestMapping("/im")   这个参数也能不代了...

public class mvcAction {

@RequestMapping(value = "/list3")

public void searchByKeyword2(String idxf, String keyword, int offset,

int limit, HttpServletResponse response) throws Exception {

 

response.getWriter().write("json txt"); 

}

 

 

 

2.Resin4 发动跟踪mvc maping

 

 

发动resin的时候儿,能看见所有的生成的map url ....feobye调试...

 

 

3. No mapping found for HTTP request with URI 

 

这个问题是更改孪注解的Url...但是,resinreload....

只要更改class,biru添加一个方法,就能reload...生效兰...

0 3
原创粉丝点击