读书人

-jsp提交表单给action时乱码

发布时间: 2012-03-25 20:55:17 作者: rapoo

求助----jsp提交表单给action时乱码

Java code
<form id="form1" name="form1" action="designer/GKD_submitSuccess?filevalue=<s:property value="filevalue"/>" method="post">


struts配置文件中设置如下
Java code
<constant name="struts.i18n.encoding" value="gb2312"/>


其中每个jsp中pageEncoding="gb2312"

求助............

[解决办法]
这问题我也碰到过,你改为method=“get”就不乱码了,如果method=“post”就必须用过滤器,没别的办法
[解决办法]
果断点加过滤器吧。。
private String encoding = "UTF-8";

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain arg2) throws IOException, ServletException {

request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
arg2.doFilter(request, response);

}
[解决办法]
你项目是GBK就把,UTF-8改为GBK吧。。

[解决办法]
Struts2乱码终极解决办法
[解决办法]
JSP: <%@ page contentType="text/html; charset=GBK"%>
[解决办法]
如果你是用<input type="image"/>这种形式来触发提交表单的话,我遇到过会执行两次。如果是这种情况不要在写document.form1.submit就可以了!
探讨
而且我在action方法里写了个控制台输出,为什么会输出两次???方法不是执行一次吗??

[解决办法]
你的参数是中文字符吧?
我也遇到过这样的问题,提交之后在后台先做一下转码,转过码的参数就是你要的啦!
String filevalue= new String(request.getParameter("filevalue").getBytes("ISO-8859-1"),"gb2312");


[解决办法]
最好编码都是utf-8
[解决办法]
String filevalue= new String(request.getParameter("filevalue").getBytes("ISO-8859-1"),"gb2312");
或者
<%@ page contentType="text/html; charset=GBK"%>
或者
request.setCharacterEncoding(“utf-8”);
response.setCharacterEncoding(“utf-8”);
[解决办法]
两种解决办法:1 在 action里过滤编码。
2 使用过滤器过滤编码。
[解决办法]
浏览器传递表单参数时编码用的UTF-8,而tomcat默认的接收参数(封装为request对象)编码为ISO-8859-1,所以传中文时乱码了
解决办法
1 在过滤器中设置request.setCharacterEncoding(“utf-8”);又由于tomcat在载入filter的时是按web.xml配置的filter顺序载入的,所以在web.xml配置时,这个过滤器要放在struts的filter前.
2 String filevalue= new String(request.getParameter("filevalue").getBytes("ISO-8859-1"),"utf-8")
ps:不知道你的struts版本是好多,我知道2.16版的中文过滤器有问题
[解决办法]
我今天也遇到了,把method改成post就好了

读书人网 >Java Web开发

热点推荐