您的位置:首页 > Web前端 > JQuery

struts2.2.1 和jQuery 进行ajax组合出现中文字符问题。

2010-11-03 00:00 525 查看
我按照struts2.2.1说明文档试试和jQuery的组合,按照如下的设置返回英文没问题。如把返回字符换成 中文字符,就会出现乱码。这里该怎么设置呢。不要说通过response 得到out 输出哦。。。。。。

struts2 action

package actions;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import com.opensymphony.xwork2.ActionSupport;
public class TextResult extends ActionSupport  {
private InputStream inputStream;
public InputStream getInputStream() {
return inputStream;
}
public String execute() throws Exception {
inputStream = new StringBufferInputStream("Hello World! This is a text string response from a Struts 2 Action.");
return SUCCESS;
}
}

struts.xml

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="ajaxtest" class="com.ray.action.AjaxAction">
<result name="success" type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>
</package>
<!-- Add packages here -->
</struts>

对于result的参数如下:

stream Result

contentType - the stream mime-type as sent to the web browser (default =
text/plain
).

contentLength - the stream length in bytes (the browser displays a progress bar).

contentDisposition - the content disposition header value for specifing the file name (default =
inline
, values are typically attachment;filename="document.pdf".

inputName - the name of the InputStream property from the chained action (default =
inputStream
).

bufferSize - the size of the buffer to copy from input to output (default =
1024
).

allowCaching if set to 'false' it will set the headers 'Pragma' and 'Cache-Control' to 'no-cahce', and prevent client from caching the content. (default =
true
)

contentCharSet if set to a string, ';charset=value' will be added to the content-type header, where value is the string set. If set to an expression, the result of evaluating the expression will be used. If not set, then no charset will be set on the header
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐