struts2.2.1 和jQuery 进行ajax组合出现中文字符问题。
2010-11-03 00:00
525 查看
我按照struts2.2.1说明文档试试和jQuery的组合,按照如下的设置返回英文没问题。如把返回字符换成 中文字符,就会出现乱码。这里该怎么设置呢。不要说通过response 得到out 输出哦。。。。。。
struts2 action
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 =
contentLength - the stream length in bytes (the browser displays a progress bar).
contentDisposition - the content disposition header value for specifing the file name (default =
inputName - the name of the InputStream property from the chained action (default =
bufferSize - the size of the buffer to copy from input to output (default =
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 =
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
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
相关文章推荐
- jquery+jsp+servlet做$.ajax交互时出现中文乱码(字符集问题)的解决方案
- 用jquery验证用户名是否有效或重复以及ajax出现的问题
- jQuery Uploadify上传插件使用中的问题 中文字符文件名转英文
- JSP页面提交后中文字符出现乱码-tomcat下中文乱码问题
- 字典序问题。在数据加密和数据压缩中常需要对特殊的字符串进行编码。给定的字母表A由26个小写字母组成。该字母表产生的升序字符串中字母从左到右出现的次序与字母在字母表中出现的次序相同,且每个字符最多出现1
- 通过ajax传值,出现的乱码和特殊字符问题
- 0.jquery 验证,以及显示出现错误的地方 1.当用jquery.validate与ajax时候特别小心在每句后面的逗号问题,如果不需要的地方加上逗号会造成页面无法进入js验证
- Struts之post提交表单出现中文乱码问题的解决方案
- JS 链接里面有中文字符,出现乱码问题
- ajax或者jQuery的ajaxSubmit出现请求根本没有发出的问题
- jQuery.ajax提交GB2312或GBK编码中文乱码问题
- php关于使用iconv(...)函数对字符进行中文转换时,遇到的一个问题
- jquery的ajax处理php返回数组,及json_encode中文为空的问题
- strutsmvc ajaxForm提交表单ie出现json文件下载问题解决
- VC轻松解析XML文件--CMarkup使用方法(解决解析中文字符出现乱码问题)
- QT 5.9版本 使用MSVC2015编译时出现中文字符乱码问题的解决方法
- JavaScript传中文值给Action出现乱码问题解决和返回ajax 返回 输出 json 乱码
- jquery.ajax的url中传递中文乱码问题的解决方法
- Gradle升级到2.2.1后出现Toast弹出中文乱码问题解决
- ASP.NET使用Jquery-Ajax向ashx传递参数中文出现乱码