频道栏目
首页 > 程序开发 > 综合编程 > 其他综合 > 正文
Filter实现浏览器是否缓存页面信息,和控制编码
2013-12-31 11:28:59      个评论    来源:董宏宇  
收藏   我要投稿
后台配置文件


	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









	
用户名:
\






点击复制链接 与好友分享!回本站首页
上一篇:走出迷宫
下一篇:Netty4学习笔记(5)-- NioEventLoopGroup继承层次结构
相关文章
图文推荐
点击排行

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站