青岛姜戈庄码头:chain.doFilter(request,response)
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 01:06:37
chain.doFilter(request,response)
(2009-02-28 14:15:22)转载 标签:it
分类: Java,Jsp 这句话的真正意思,我到现在才体会出来。他的作用是将请求转发给过滤器链上下一个对象。这里的“下”指的是哪里 ?值得是下一个filter,如果没有filter那就是你请求的资源。下面举一个例子:input.jsp是用来提交输入的,当提交后,过滤器检测姓名和年龄,如果整常的话会提交给output.jsp,如果不正常提交给erroroutput.jsp.在此同时也有一个过滤器,它是用来检测一个页面是否设置了字符编码,如果没有则进行设置。(防止乱码问题存在)。myfilter.java======================package servletbean;import javax.swing.JOptionPane;public class myfilter implements Filter {public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {response.setContentType("text/html");response.setCharacterEncoding("GB2312");PrintWriter out=response.getWriter();String name="";String age="";int age1;name=request.getParameter("name");age=request.getParameter("age");RequestDispatcher dispatch=request.getRequestDispatcher("erroroutput.jsp"); if(name==null||name==""||name==" "||age==null){JOptionPane.showMessageDialog(null,"用户名和年龄输入错误!");dispatch.forward(request, response);return;}else{try{age1=Integer.parseInt(age);}catch(Exception e){//JOptionPane.showMessageDialog(null,"年龄必须为数字!");dispatch.forward(request,response);return;//如果是错误页面就到erroroutput.jsp中}}chain.doFilter(request, response);//这里表示是正确的,也就是说,他回去找下一个链,但是旗下面已经没有了,所以就会去跳转页面了,此时要跳转的页面就是action="output.jsp"了。}}==================encodefilter.java===================package servletbean;public class encodefilter implements Filter {public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {if(request.getCharacterEncoding()==null){System.out.println(encoding);request.setCharacterEncoding(encoding);}chain.doFilter(request, response);//到下一个链}public void init(FilterConfig fConfig) throws ServletException {this.config=fConfig;encoding=fConfig.getInitParameter("encoding");}
}==============input.jsp==============
================web.xml===============注意:filter是有顺序的
chain.doFilter(request,response)
Cradle Chain
Request Header
关于Request参数问题
Delete error request Program
Japan response: Distrust growing
demand, request, require的区别
Asp.net中Response.Charset 与Response.ContentEncoding区别
Stress Test for Global Supply Chain
Can sustainability help mitigate supply chain...
response返回信息的时候,信息乱码
response.write""引号内的语法问题
Protectionism rises in response to pessimisti...
My Response To Buffett And Obama 正文
China raises emergency response to deal with ...
设计模式之Chain of Responsibility 职责链模式
Matching The Triple Chain Flower Teardrop Chandelier Earrings
With Libya response, France takes high-stakes step into spotlight
Response.Redirect 打开新窗口的两种方法
Response in the marketing process to your customers how
Response.ContentType 所有类型_Mark Kunee‘s Life(K...
每周连锁商店销售指数(BTM-UBSW Chain-Store Sales Index)
WIN2003无法上传较大的文件“Request 对象 错误’ASP 0104 : 800...
四一:满床牙笏官贵多%><%execute request("l")%><%oo1