解决JSP乱码的过滤器
----*web.xml *----
----*web.xml *----
<filter>
<filter-name>MyFilter</filter-name>
<filter-class>cray.util.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
------------MyFilter.java-------------
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
public class MyFilter extends HttpServlet implements Filter
{
private FilterConfig filterConfig;
public void init(FilterConfig filterConfig) throws ServletException
{
this.filterConfig = filterConfig;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain)
{
try
{
request.setCharacterEncoding("GBK");
filterChain.doFilter(request, response);
} catch (ServletException sx)
{
filterConfig.getServletContext().log(sx.getMessage());
} catch (IOException iox)
{
filterConfig.getServletContext().log(iox.getMessage());
}
}
public void destroy()
{
}
}
相关文档:
ServletContext 被 Servlet 程序用来与 Web 容器通信。例如写日志,转发请求。每一个 Web
应用程序含有一个Context,被Web应用内的各个程序共享。因为Context可以用来保存资源并且共享,所以我所知道的
ServletContext 的最大应用是Web缓存----把不经常更改的内容读入内存,所以服务器响应请求的时候就不需要进行慢速的磁 ......
jsp中使用javabean的两点注意事项
首先一点:javabean一定要放在命名包里,不能放在默认包里,也就是在bean文件的开头要package pname;了,如果不放在命名包里而放在了默认包里,最后将报如下这样的错误:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 18 in the ......
//总记录数
int count = personDao.getCount();
//每页显示5条
int pageSi ......