MyRequestProcessor.java
上传用户:jishiqi_cj
上传日期:2022-08-08
资源大小:24765k
文件大小:1k
- package classmate;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts.action.RequestProcessor;
- import org.apache.struts.config.ForwardConfig;
- import org.apache.commons.logging.Log;
- public class MyRequestProcessor extends RequestProcessor {
-
- public MyRequestProcessor() {}
-
- protected boolean processPreprocess( HttpServletRequest request,
- HttpServletResponse response ){
-
- boolean continueProcessing = true;
-
- // Get the name of the remote host and log it
- String remoteHost = request.getRemoteHost( );
- log.info( "Request from host: " + remoteHost );
-
- // Make sure the host is from one that you expect
- if (( remoteHost == null || !remoteHost.startsWith( "127."))){
- // Not the localhost, so don't allow the host to access the site
- continueProcessing = false;
-
- try{
- response.sendRedirect( "/S02_Extend/error.jsp");
- }catch( Exception ex ){
- log.error("Problem sending redirect from processPreprocess()") ;
- }
- }
- return continueProcessing;
- }
- }