过滤器(练习)

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <form action="test4.jsp" method="post">
11 <textarea rows="8" cols="50" name="name">
12 </textarea>
13 <input type="submit" value="提交">
14 </form>
15 </body>
16 </html>
 1 package hanqi;
 2 
 3 import java.io.IOException;
 4 import javax.servlet.Filter;
 5 import javax.servlet.FilterChain;
 6 import javax.servlet.FilterConfig;
 7 import javax.servlet.ServletException;
 8 import javax.servlet.ServletRequest;
 9 import javax.servlet.ServletResponse;
10 public class Test3Filter implements Filter 
11 {
12     public Test3Filter() 
13     {
14        
15     }
16 
17     public void destroy()
18     {
19     
20     }
21 
22     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
23     {
24         String a=request.getParameter("name");
25         String b=a.replace("傻逼", "?");
26         request.setAttribute("name1", b);
27         chain.doFilter(request, response);
28     }
29 
30 
31     public void init(FilterConfig fConfig) throws ServletException 
32     {
33         
34     }
35 
36 }
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <%
11 String a=request.getAttribute("name1").toString();
12 %>
13 <textarea rows="8" cols="50">
14 <%=a %>
15 </textarea>
16 </body>
17 </html>

posted @ 2016-07-04 08:44  明天会更好!!!!  阅读(182)  评论(0)    收藏  举报