然后在系统的过滤器中配置下:
package com.jframe.http;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ygsoft.basic.dao.HibernateDaoSupport;
import com.ygsoft.util.LocalThreadBean;
public class EncodingFilter
implements Filter
{
private FilterConfig config;
private String targetEncoding;
private LocalThreadBean localThreadBean;
public EncodingFilter()
{
config = null;
targetEncoding = "GB18030";
localThreadBean =new LocalThreadBean();
}
public void init(FilterConfig config)
throws ServletException
{
this.config = config;
try
{
String temp = config.getInitParameter("encoding");
if(temp != null)
targetEncoding = temp;
}
catch(Exception exception) { }
}
public void destroy()
{
config = null;
targetEncoding = null;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
HttpServletRequest hreq = (HttpServletRequest)request;
HttpServletResponse hres = (HttpServletResponse)response;
request.setCharacterEncoding(targetEncoding);
chain.doFilter(request, response);
LocalThreadBean.setContext((HttpServletRequest)request);
// 关闭遗漏的 Session
HibernateDaoSupport.closeSessionList();
}
}
当然,还需要在web.xml中加上此过滤bean了。
上一页 [1] [2]
责任编辑:小草