struts2.2.1 和jQuery 进行ajax组合出现中文字符问题。
我按照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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
java端使用UrlEncoder和UrlDecoder两个类
js端使用encodeURI、encodeURIComponent和decodeURI函数