关于struts2中传入中文参数然后显示到页面出现乱码
来源:互联网 发布:网页设计软件哪个好 编辑:程序博客网 时间:2024/05/21 10:33
struts2传入中文出现乱码的情况
今天写了一个struts2出现了中文乱码,实现的动能是这样的
,
设计一个表单,其中type代表的是数字,type1输入的是中文,其中表单中action是一个struts2的action,单击提交以后返回成功视图的后吧type和type1中的数据取出来
其中action的部分代码:
<action name="useraction" class="action.UserAction">
<result name="success" type="dispatcher">/success.jsp</result><!-- 这个是服务器跳转,传递参数是在valuestack中 -->
<result name="test" type="redirect">
<param name="location">success.jsp</param>
<param name="type">${type}</param>
<param name="type1">${type1}</param>
</result>
<result name="error">/error.jsp </result>
</action>
<result name="success" type="dispatcher">/success.jsp</result><!-- 这个是服务器跳转,传递参数是在valuestack中 -->
<result name="test" type="redirect">
<param name="location">success.jsp</param>
<param name="type">${type}</param>
<param name="type1">${type1}</param>
</result>
<result name="error">/error.jsp </result>
</action>
这里用到的result type是dispatcher这个是默认的类型,是服务器跳转,其中的参数都保存到valuestack中(值栈)
在success页面中取出type和type1的值
success.jsp的部分代码
取出值 <s:property value="type"/><br/>
汉字<s:property value="type1"/><br/>
汉字<s:property value="type1"/><br/>
这样什么都不做取出后显示中文乱码,struts2其实也做了配置编码的设计(<constant name="struts.i18n.encoding" value="utf-8"/>配置常量)但是但是在struts2
中出现bug,这样配置以后任然会出现乱码,我查的是在web.xml中配置的struts2过滤器出现问题,
<filter-class>中配置以前的版本就能够解决中文乱码,但是我返回struts2.0的配置以后仍然会出现中文乱码
最后我想到用过滤器的方法进行编码的过滤,在web.xml中配置一个过滤器
部分代码如下
web.xml
<!-- 编码过滤器 -->
<filter>
<filter-name>encoding</filter-name>
<filter-class>filterdemo.EcodingFilter</filter-class>
<init-param>
<param-name>charset</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>encoding</filter-name>
<filter-class>filterdemo.EcodingFilter</filter-class>
<init-param>
<param-name>charset</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
EcodingFilter.java文件
这里注意的一点是进行编码设计以后必须把请求继续传递下去,chain。doFilter()函数进行传递
这样设置以后就不会出现中文乱码了
0 0
- 关于struts2中传入中文参数然后显示到页面出现乱码
- jsp页面中href到另一个页面传递参数,参数中有中文出现乱码的解决办法!
- 【坑】JSP中使用jsp:param传入参数的时候出现中文乱码
- JSP中使用jsp:param传入参数的时候出现中文乱码
- 中文作为参数传入 window.showModalDialog出现乱码的解决办法
- 中文作为参数传入 window.showModalDialog出现乱码的解决方法
- Gridview中使用HyperlinkField传输中文参数到下一个页面中,接收后出现乱码的解决方案
- 用name作为参数查询记录时,页面中显示中文名字时出现乱码的解决方法!
- 关于struts2中的显示页面乱码问题
- 页面传输中文到服务器乱码,页面显示乱码
- 页面jsp编码utf-8,传递中文参数到java后台出现乱码
- struts2中form提交到action中的中文参数乱码问题解决办法(包括取中文路径)
- struts2中form提交到action中的中文参数乱码问题解决办法(包括取中文路径)
- struts2中form提交到action中的中文参数乱码问题解决办法(包括取中文路径)
- JSP中乱码问题解决(一、JSP页面显示乱码,二、表单提交中文时出现乱码,三、数据库连接出现乱码,四、数据库的显示乱码 )
- jsp页面上传文件到servlet获取到路径中有中文出现乱码
- Struts2中使用GET方式传递中文参数出现乱码的解决方案
- 关于页面包含中文参数传递到后台有乱码的解决办法
- SecureCRT连不上Linux虚拟机的一种可能
- PLM(Product Lifecycle Management)System
- 《Java程序设计基础》 第6章手记
- C语言库函数一
- C++精进篇(四)之―结构体和头文件
- 关于struts2中传入中文参数然后显示到页面出现乱码
- x86汇编--(一)寄存器功能、寻址方式、伪指令总结
- 条款1:理解模板类型推断
- hdu 2609 how many
- C++精进篇(二)之―指针和引用
- iOS职位面试问题及答案
- 《夜曲》
- Git 教程 - Git 基本用法
- HBase之HFile解析