Filter

xiaoxiao2021-03-05  30

package com.Servlet.filter; import java.io. *; import javax.servlet *;. import javax.servlet.http *;. import javax.servlet.Filter; public class myfilter implements Filter {private FilterConfig filterConfig = null; public void init (FilterConfig filterConfig) {this.filterConfig = filterConfig;} public void doFilter (ServletRequest req, ServletResponse res, FilterChain chain) throws ServletException, IOException {try {res.setContentType ( "text / html; charset = GBK"); PrintWriter OUT = Res. Getwriter (); string remoteaddr = (httpservletRequest) REQ) .GETREMOTEADDR (); if (RemoteAddr.indexof ("127.0.0.1")! = -1) || (RemoteAddr.indexof ("localhost" )! = -1)) {// Here to determine out.println (" "); out.println ("

Haha, IP 127.0.0.1 and IP Localhost cannot access this website ~~ "); Out.Println (" "); out.close (); return;} else {Out.println (" < Head> "); out.println ("

Congratulations, you have successfully accessed this website ~~ "); Out.Println (" "); out.close ();}} catch (exception e) {E.PrintStackTRA CE ();}} public void destroy () {}}

转载请注明原文地址:https://www.9cbs.com/read-37498.html

New Post(0)