springmvc ajax请求以及json
2016-08-26 20:27
211 查看
1.使用json格式数据进行前台与后台间数据传递
需要导入的包:jackson-core-asl-1.9.13.jar jackson-mapper-asl-1.9.13.jar
需要配置:
在jsp中加:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- base需要放到head中 -->
<base href=" <%=basePath%>">
在web.xml配置中: <servlet-mapping> <servlet-name>名字</servlet-name> <!-- 这里可以用 / 但不能用 /* ,拦截了所有请求会导致静态资源无法访问,所以要在spring3-servlet.xml中配置mvc:resources --> <url-pattern>/</url-pattern> </servlet-mapping>
在MVC.XML中配置:
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> <property name="objectMapper"> <bean class="org.codehaus.jackson.map.ObjectMapper"> <property name="dateFormat"> <bean class="java.text.SimpleDateFormat"> <constructor-arg index="0" type="java.lang.String" value="yyyy-MM-dd HH:mm:ss"/> </bean> </property> </bean> </property> </bean> <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"/> <bean id="requestMappingHandlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter"/> <ref bean="stringHttpMessageConverter"/> </list> </property> </bean>
相关文章推荐
- SpringMVC3.2 处理Ajax请求时返回json字符串的中文乱码问题
- 【Spring学习笔记-MVC-5】利用spring MVC框架,实现ajax异步请求以及json数据的返回
- java ajax 请求后获取 json 数据 以及 使用 解析 ,解惑
- 关于AJAX请求后台数据,接收后台返回的JSON数据,以及前台遍历json数据和append追加元素。
- 使用springMVC注解@ResponseBody与jackson工具类在ajax请求中实现对象与json之间的相互转化
- ajax请求解析springmvc返回的json数据
- 使用ajax请求SpringMVC返回Json出现乱码解决方法
- Struts学习_Jquery发送ajax请求以及datatype参数为text/JSON方式
- SpringMVC处理普通请求异常以及,ajax异常
- SpringMVC中使用Ajax POST请求以json格式传递参数服务端通过request.getParameter("name")无法获取参数值问题分析
- SpringMVC Ajax请求时返回json中文字符串的乱码问题的解决方案
- 关于SpringMVC 中服务器端如何响应 AJAX 请求(即controller是如何返回json的)
- SpringMVC处理Ajax请求(请求数据为 json 格式字符串)
- ajax跨域,使用json,crossDomain,请求返回状态200,但是走的error的原因以及解决方法
- AJAX,JSON,JSONP以及跨域请求
- Jquery发送ajax请求以及datatype参数为text/JSON方式
- SpringMVC环境下实现的Ajax异步请求(JSON格式数据) 推荐
- SpringMVC环境下实现的Ajax异步请求JSON格式数据
- @RequiresPermissions 控制权限的异常处理以及Ajax方式请求时返回json
- Ajax的基础请求以及获取JSON的两种解析方式