springmvc的servlet配置详解 源码下载

<!-- web.xml配置 -->
<!-- ====================================== -->源码下载地址<a target=_blank href="http://download.csdn.net/detail/qq_28051649/9395615">http://download.csdn.net/detail/qq_28051649/9395615</a>
 <p><?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="<a target=_blank href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>" 
   xmlns="<a target=_blank href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a>" 
   xmlns:web="<a target=_blank href="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd</a>" 
   xsi:schemaLocation="<a target=_blank href="http://java.sun.com/xml/ns/javaee">http://java.sun.com/xml/ns/javaee</a> <a target=_blank href="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd</a>" id="WebApp_ID" version="3.0">
  <display-name>com.dcfs.zhangfyb.springmvc</display-name>
  
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <servlet> 
     <servlet-name>springmvc</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
        <init-param>  
            <!-- 加载springmvc的xml到 spring的上下文容器中 -->  
            <param-name>contextConfigLocation</param-name>  
            <param-value>/WEB-INF/springmvc/springmvc-servlet.xml</param-value>  
        </init-param>  
     <load-on-startup>1</load-on-startup> 
  </servlet> 
  
  <servlet-mapping> 
     <servlet-name>springmvc</servlet-name> 
       <!-- 由springmvc拦截所有请求 -->
     <url-pattern>/</url-pattern> 
  </servlet-mapping></p><p></web-app></p>
<!--springmvc-servlet.xml文件配置  -->
<p><?xml version="1.0" encoding="UTF-8"?></p><p><beans xmlns="<a target=_blank href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>"       
       xmlns:xsi="<a target=_blank href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"
       xmlns:p="<a target=_blank href="http://www.springframework.org/schema/p">http://www.springframework.org/schema/p</a>"   
       xmlns:mvc="<a target=_blank href="http://www.springframework.org/schema/mvc">http://www.springframework.org/schema/mvc</a>"  
       xmlns:context="<a target=_blank href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a>"    
       xsi:schemaLocation="     
           <a target=_blank href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a>     
           <a target=_blank href="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">http://www.springframework.org/schema/beans/spring-beans-3.0.xsd</a>  
           <a target=_blank href="http://www.springframework.org/schema/mvc">http://www.springframework.org/schema/mvc</a>    
           <a target=_blank href="http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd</a>  
           <a target=_blank href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a>     
           <a target=_blank href="http://www.springframework.org/schema/context/spring-context-3.0.xsd">http://www.springframework.org/schema/context/spring-context-3.0.xsd</a> ">   
           
    <!-- 设置使用注解的类所在的jar包 --> 
    <context:component-scan base-package="com.dcfs.zhangfyb.controller" />  
    
 <mvc:annotation-driven ></mvc:annotation-driven>
    
    <mvc:resources mapping="/*.html" location="/" />  
    <mvc:resources mapping="/javascript/**" location="/js/" />  
    <mvc:resources mapping="/styles/**" location="/" /> 
    <mvc:resources mapping="/images/**" location="/" />
    <mvc:default-servlet-handler  />  
    
    
    
    <!-- ViewResolver --> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF"/> 
        <property name="suffix" value=".jsp"/> 
    </bean>
     
</beans></p> 
html页面
<!DOCTYPE html>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Insert title here</title>
  <script type="text/javascript" src="js/jquery-1.11.0.js"></script> 
  <script type="text/javascript" src="js/test.js"></script>  
 </head>
 <body>
  姓名 <input id="userName" type="text" name="userName"> 
      <input type="button" id="resolveJsonObject" value="json对象">  
  
 </body>
</html>

 

 

/**test.js文件                 ** */
$(document).ready(  function(){  
           $("#resolveJsonObject").click(function(){  
            var userName=encodeURI($("#userName").attr("value"));  
            var user = {userName: userName};
            $.ajax({  
             <a target=_blank href="'/com.dcfs.zhangfyb.springmvc/user/data/resolveObject">url:"/com.dcfs.zhangfyb.springmvc/user/data/resolveObject</a>",  
             data:"orderJson=" + user,
             success: function(data){  
              
             }
            })
           });
   })
java类
<p>package com.dcfs.zhangfyb.controller;</p><p>import java.io.IOException;</p><p>import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;</p><p> </p><p>import net.sf.json.JSONObject;</p><p>import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;</p><p>
@Controller @RequestMapping("/user/data") 
public class MVCController {</p><p> @RequestMapping("/resolveObject") 
 public void resolveJsonObject(HttpServletRequest request,HttpServletResponse response) throws IOException{  
   
  String str =  request.getParameter("orderJson");
  JSONObject jb = new JSONObject();  
  String ss = (String) jb.fromObject(str).get("userName");  
  System.out.println(ss);   </p><p> }
}</p>
 



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值