<!-- 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>