配置文件:
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=utf-8</value>
<value>text/html;charset=utf-8</value>
<value>text/json;charset=utf-8</value>
<value>application/json;charset=utf-8</value>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="text" />
<constructor-arg index="1" value="plain" />
<constructor-arg index="2" value="UTF-8" />
</bean>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
</list>
</property>
</bean>
后台先用
//对json中的特殊字符进行处理
str = str.replace(">", "");
str = str.replace("<", "");
str = str.replace("\'", "");
str = str.replace("\\", "");//对斜线的转义
str = str.replace("\n", "");
str = str.replace("\r", "");
str = str.replace(";", " ");
再把字符串用
JSONObject listJson = JSONObject.fromObject(str);
格式成JSON
ModelAndView mv = new ModelAndView("info", map);
返回
JSP页面使用C标签解析
<c:forEach items="${}" var="list" varStatus="s">
${s.index}
</c:forEach>