<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body><formAction= "newfile3.jsp"Method= "POST"><inputtype= "text"name= "Name"><inputtype= "Submit"value= "Submit"></form></Body></HTML>
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body><%StringN=Request.getattribute ("name1"). toString ();%><inputtype= "text"value= "<%=n%>"></Body></HTML>
PackageCom.hanqi.web;Importjava.io.IOException;ImportJavax.servlet.Filter;ImportJavax.servlet.FilterChain;ImportJavax.servlet.FilterConfig;Importjavax.servlet.ServletException;Importjavax.servlet.ServletRequest;ImportJavax.servlet.ServletResponse; Public classTestFilter1ImplementsFilter { PublicTestFilter1 () {} Public voiddestroy () {} Public voidDoFilter (ServletRequest request, servletresponse response, Filterchain chain)throwsIOException, servletexception {String str=request.getparameter ("name"); String str1=str.replaceall ("The", "*"); Request.setattribute ("Name1", STR1); System.out.println (STR1); Chain.dofilter (request, response); } Public voidInit (Filterconfig fconfig)throwsservletexception {}}
<filter> <display-name>TestFilter1</display-name> <filter-name>TestFilter1< /filter-name> <filter-class>com.hanqi.web.testfilter1</filter-class> </filter> <filter-mapping> <filter-name>TestFilter1</filter-name> < Url-pattern>/newfile3.jsp</url-pattern> </filter-mapping>
Practice filtering sensitive words for user input