解决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()
{
}
}
相关文档:
在JSP中的如果使用 "相对路径" 则有可能会出现问题.
因为 网页中的 "相对路径" , 他是相对于 "URL请求的地址" 去寻找资源.
上面这句话是什么意思呢 ?
举个例子:
假如我们有一个项目: MyApp
在该项目下, 有一个jsp文件夹
该文件夹下包括:
login.jsp // ......
//总记录数
int count = personDao.getCount();
//每页显示5条
int pageSi ......
jsp 缓存, html 缓存, ajax缓存,解决方法
url:http://blog.csdn.net/oklzh/archive/2009/08/14/4445722.aspx
有关页面缓存问题.这个问题上网找了好多.但发觉各种解决方法,都彼此分离,没有一篇统一的解决方法,本人近日,也遇到了页面缓存的问题,根据网上各页面缓存的解答,做了一个总结。
1.服务器端缓存的问题 ......
package DBbean;
import java.sql.*;
public class ConnBean
{
private Connection con;
//初始化连接。
public ConnBean()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
......
主要在jsp页面加入
<%@ page contentType="application/msexcel;charset=GBK"%>
<%
response.setHeader("Content-disposition",
"attachment; filename=shouExcel.xls");
%>
完整页面如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8 ......