struts 关于从数据库读出数据,页面汉字乱码 在server.xml文件找到<Connector .../>,然后加上<Connector ... URIEncoding="GBK"/>,你试一试吧! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我自己测试没问题的..给个例子你试一下!import java.io.IOException;import javax.servlet.Filter;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; } 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; } protected String selectEncoding(ServletRequest request) { return (this.encoding); }}web.xml中配置一下..就OK了..不需要在 Action中在设置编码了 <filter> <filter-name>setCharsEncoding</filter-name> <filter-class>SetCharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>gb2312</param-value> </init-param> </filter> 哦忘了贴了 过滤/*就可以了 <filter-mapping> <filter-name>setCharsEncoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 急!!!关闭网页时怎样让session失效? list 数据装换 Map jbpm4.3 task.getFormResourceName() 为空,怎么回事啊? myEclipse8.0自带struts2有问题? ssh项目如何实现页面打印税务发票????? webservice中如何带附件 急急急~~~~Unsupported Media Type 什么方法可以定时重启tomcat? 大家知道怎么在linux下配置J2EE吗? 用BufferedReader封装socket的输入流,返回了null,怎么处理 类型转换问题? 我想问一下..为什么这条语句不执行呢啊..想不通..请大家帮忙
import java.io.IOException;
import javax.servlet.Filter;
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; } 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; } protected String selectEncoding(ServletRequest request) { return (this.encoding); }
}
web.xml中配置一下..就OK了..不需要在 Action中在设置编码了
<filter> <filter-name>setCharsEncoding</filter-name>
<filter-class>SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>gb2312</param-value>
</init-param>
</filter>
<filter-name>setCharsEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>