乱码问题 问题是这样的:我在一个jsp页面的输入框里输入中文后,提交请求后在后台输出的确是乱码。jsp页面的那三个编码都设置的是gb2312了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把代码贴出来,提交要用 post 方式哦 <%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>管理员登录</title></head><body><form method="post" action="/library/login.do"> <table width="90%" border="0" cellspacing="0" cellpadding="1"> <tr> <td>用户名 <br /></td> <td><input type="text" name="adminName" size="10"/></td> </tr> <tr> <td>密码 </td> <td><input type="password" name="adminPassword" size="10"/></td> </tr> <tr> <td><input type="submit" name="Submit" value="提交" /></td> <td><input type="reset" name="Submit2" value="重置" /></td> </tr> </table> <p> </p></form></body></html> 加个过滤器,在web.xml配置一下import java.io.IOException;import javax.servlet.*;public class SetCharactorEncodingFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws IOException, ServletException { request.setCharacterEncoding("GBK"); chain.doFilter(request, response); } public void init(FilterConfig filterConfig) throws ServletException { }}XML code <filter> <filter-name>Set Character Encoding</filter-name> <filter-class>cn.ac.sict.ietd.util.SetCharactorEncodingFilter</filter-class> </filter> <filter-mapping> <filter-name>Set Character Encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 一般有中文的表单提交,我设置字符集统一为UTF-8,建议楼主都改为UTF-8试试。还有一种就是写jsp编码过滤器。这里有一篇文章总结的很好,关于jsp提交中文乱码的,建议楼主看一下http://blog.csdn.net/jason_hisoft/archive/2008/03/18/2194574.aspx 乱码问题1、保持前后台的编码格式一致,包括数据库的编码格式2、filter可以设置编码格式、在tomcat server.xml可以设置URL传值的编码格式3、如果1、2都没有错,请仔细检查配置是否有问问题,或许是配置没有更新等低级错误 跪求一个S2SH项目整合的源代码给我 菜鸟求助。。急 Spring 如何互相注入,或如何互相引用 jquery 与struts2中的标签为何不能这样使用? Hibernate3-0连接数据库方法(谢谢大家了) myeclipse部署web工程的困惑 求JavaScript一个简单例子!!着急ing 关于weblogic下载的问题 EJB从数据库取数问题 编译Spring3.0.x版本Context项目出现的pom.xml错误 没事做,发个贴,回答一个深奥的问题——共线和共面 ireport 可以动态增、删字段吗?
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>管理员登录</title>
</head><body>
<form method="post" action="/library/login.do">
<table width="90%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td>用户名 <br /></td>
<td><input type="text" name="adminName" size="10"/></td>
</tr>
<tr>
<td>密码 </td>
<td><input type="password" name="adminPassword" size="10"/></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="提交" /></td>
<td><input type="reset" name="Submit2" value="重置" /></td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
web.xml配置一下import java.io.IOException;
import javax.servlet.*;public class SetCharactorEncodingFilter implements Filter {
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)throws IOException, ServletException { request.setCharacterEncoding("GBK");
chain.doFilter(request, response);
} public void init(FilterConfig filterConfig) throws ServletException {
}
}
XML code
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>cn.ac.sict.ietd.util.SetCharactorEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
还有一种就是写jsp编码过滤器。
这里有一篇文章总结的很好,关于jsp提交中文乱码的,建议楼主看一下
http://blog.csdn.net/jason_hisoft/archive/2008/03/18/2194574.aspx
乱码问题1、保持前后台的编码格式一致,包括数据库的编码格式2、filter可以设置编码格式、在tomcat server.xml可以设置URL传值的编码格式3、如果1、2都没有错,请仔细检查配置是否有问问题,或许是配置没有更新等低级错误