---
title: "struts  json  引号 &quot; 问题"
author: "wangsong76"
date: "2009-02-12T17:22:24Z"
tags: ["Bean", "JSP", "Struts", "json"]
categories: ["企业架构"]
slug: "struts-json-quot"
draft: false
lastmod: "2009-02-12T17:48:28Z"
id: 327491
url: "https://wangsong76.iteye.com/blog/327491"
---

在使用json从后台传递数据到前台时，如果是这样的：

后台向页面发送一个消息，后台写法：
String str="{\"rows\":[{\"info\":\"系统中已有该工号\"}]}";
request.setAttribute("MessageInfo",str);
前台jsp页面中获取写法
result="<%=request.getAttribute("MessageInfo")%>";
或者
result="<bean:write name="MessageInfo"/>";

那么前台获取的值就是：
{&quot;rows&quot;:[{&quot;info&quot;:&quot;系统中已有该工号&quot;}]}
而我们想要的是
{"rows":[{"info":"系统中已有该工号"}]}

造成这个样的情况是因为：bean:write 的属性filter默认值为true,
改为：
<bean:write name="MessageInfo"  filter="false"/> 
这样就能正常获取到值了。

而采用result="<%=request.getAttribute("MessageInfo")%>";
则没有这个问题。

