后台配置文件jqueryeasyui index.html index.htm index.jsp default.html default.htm default.jsp ResponseHeaderFilter tk.Martin.filterDemo.filter.ResponseHeaderFilter Cache-Control max-age=1000 ResponseHeaderFilter *.css UserServlet tk.Martin.filterDemo.servlet.UserServlet UserServlet /userOper.do
这是控制是否浏览器缓存的代码package tk.Martin.filterDemo.filter;import java.io.IOException;import java.util.Enumeration;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class ResponseHeaderFilter implements Filter { FilterConfig filterConfig; @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub HttpServletRequest request=(HttpServletRequest) req; HttpServletResponse response=(HttpServletResponse) res; for(Enumeration e=filterConfig.getInitParameterNames();e.hasMoreElements();){ String headerName=(String) e.nextElement(); System.out.println("========================="+headerName+"==================================="); response.addHeader(headerName, filterConfig.getInitParameter(headerName)); } chain.doFilter(request, response); } @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub this.filterConfig=filterConfig; }}
这是控制上传的编码的Filter过滤类package tk.Martin.filterDemo.filter;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 CharacterEncodingFilter implements Filter { private String characterEncoding; @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub request.setCharacterEncoding(characterEncoding); chain.doFilter(request, response); } @Override public void init(FilterConfig filterConfig) throws ServletException { // TODO Auto-generated method stub this.characterEncoding = filterConfig.getInitParameter("encoding"); System.out.println("页面编码方式===============" + this.characterEncoding + "================================="); }}
这是前台的jsp的代码<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@include file="/common/tag.jsp"%><%@include file="/common/jquery.jsp"%>My JSP 'index.jsp' starting page