1.springmvc.xml配置
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
< property name="supportedMediaTypes">
<list>
<value>text/json;charset=UTF-8</value>
</list>
</property>
</bean>
<bean id="stringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
< list>
< value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
< property name="messageConverters">
<list>
<!-- JSON转换器 -->
<ref bean="mappingJacksonHttpMessageConverter" />
<!--String字符串转换 写入响应消息中-->
<ref bean="stringHttpMessageConverter"/>
</list>
</property>
</bean>
2.加ResponseBody注解 返回字符串类型参数
@ResponseBody
@RequestMapping(value="/abc")
public String getABC(HttpServletRequest request,HttpServletResponse response){
return "1";
}
3.前端Ajax 根据返回的值 显示不同的内容
$.ajax({
url: "<%=request.getContextPath()%>/abcCtrl/abc.action",
type: "post",
data: params,
dataType:"text",
success: function (result) {
if(result == 1){
;
}else{
;
}
}
});