页面设置为<%@ page contentType="text/html;charset=gb2312"%>
如果页面中没有中文字符则在提交Action中用:
new String(ba_lubeForm.getClname().getBytes("ISO-8859-1"),"gb2312")可以将转换为中文字
但是,页面中包含中文字符如:
<td valign="left" width=33%>
名称:<input type="text" name="clname" size="15">
</td>
则在提交Action中还是乱码望高手指点
如果页面中没有中文字符则在提交Action中用:
new String(ba_lubeForm.getClname().getBytes("ISO-8859-1"),"gb2312")可以将转换为中文字
但是,页面中包含中文字符如:
<td valign="left" width=33%>
名称:<input type="text" name="clname" size="15">
</td>
则在提交Action中还是乱码望高手指点
解决方案 »
- JDK升级对于版式的影响
- 学习java的顺序
- javascript向jsp传递参数然后回显,请高手帮忙,谢谢!
- 关于session是否已失效,除了到达设定的时间,如何在关闭浏览器时设定session失效,急
- 在线等待。。。动态加载类和类方法的问题?急!!!
- jdbc连接SQL Server 2000系统配置问题!
- 高分请教"10.5.1 500 Internal Server Error"的问题
- 请问怎样在JSP中画图呀?
- 从上页得到的String[] strSystemNo,如何在点按钮时提交到下页
- 急救!一个关于jsp的小问题!局部变量和全局变量!
- <!--#include file="top.htm" -->的问题
- jdk1.5+tomcat5.0怎么配才能运行jsp?
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;public class SetCharacterEncodingFilter implements Filter {
protected String encoding = null; protected FilterConfig filterConfig = null; protected boolean ignore = true; public void destroy() {
this.encoding = null;
this.filterConfig = null;
} protected String selectEncoding(ServletRequest request) {
return (this.encoding);
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
} chain.doFilter(request, response);
} public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false; }}
在JSP页面中加入:
如果还不行正常显示,则还要进行下面的转换:
如:name=new String(name.getBytes("ISO-8859-1"),"GBK");
就不会出现中文问题了。