在我的jsp页面中有一个表单,采用post方式提交。在js里面用form.submit()方法提交之后,在action里面用request.getParameter()方法获取到的中文参数为乱码,jsp页面是用GB18030编码,web.xml里面也配置了过滤器,把所有请求的编码方式设置为GB18030,过滤器确实也生效了,在action中request.getCharactorEncoding()打印出来编码方式也为GB18030。在网上找了无非就是叫加过滤器、request.setCharactor()方法之类试过了全都不管用。
WebShpere的server中配置jvm通用参数,也还是不管用。jsp页面代码 <%@ page language="java" pageEncoding="GB18030"%>
<html>
<head>
……
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
……
</head>
<body>
<form id="template" method="post" onsubmit="return doValidate() action='***action|***.action'">
……
<form>
<body>
</html>
action代码public String saveTemplate() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
log.debug("encoding is={}",request.getCharactorEnCoding());//得到GB18030,在这里再使用request.setCharactorEncoding("GB18030");也不管用
String name = request.getParameter("name");//乱码
}
在开发的时候使用的myEclipse8.5自带的tomcat6,表单使用post方式也为乱码,但是换成get方式之后tomcat下就正常了。部署到WebSphere6.1下面之后,get方式也是乱码,post方式也是乱码,而且我仔细看了下,貌似乱码还不一样。请教下各位大虾这是什么原因或者怎么解决啊,万分感激!
WebShpere的server中配置jvm通用参数,也还是不管用。jsp页面代码 <%@ page language="java" pageEncoding="GB18030"%>
<html>
<head>
……
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
……
</head>
<body>
<form id="template" method="post" onsubmit="return doValidate() action='***action|***.action'">
……
<form>
<body>
</html>
action代码public String saveTemplate() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
log.debug("encoding is={}",request.getCharactorEnCoding());//得到GB18030,在这里再使用request.setCharactorEncoding("GB18030");也不管用
String name = request.getParameter("name");//乱码
}
在开发的时候使用的myEclipse8.5自带的tomcat6,表单使用post方式也为乱码,但是换成get方式之后tomcat下就正常了。部署到WebSphere6.1下面之后,get方式也是乱码,post方式也是乱码,而且我仔细看了下,貌似乱码还不一样。请教下各位大虾这是什么原因或者怎么解决啊,万分感激!
服务器上WebSphere,用其他框架的请求和相应都是正常的,就struts2的action有问题。所以才在自己机器上装的WebSphere来调试,浪费很多时间还是搞不定。。
所以现在很乱啊,tomcat上get方式没问题了,但是WebSphere上无论get还是post都有问题。filter是有的,而且从我打的log看也肯定生效了。同时我的action里也是在打印出request编码方式GB18030之后才取的值。
templateName = new String(templateName.getBytes("ISO-8859-1"), "GB18030");
嗯,这个filter是在所有的过滤器之前的。
请不要使用这些配置。
----------------嗯--------------------
如果上面的说法依然不中,
那只有一个问题了:你的过滤器写得有问题。