myrequestprocessor.java
来自「这是《Struts开发入门与项目实践》的源代码」· Java 代码 · 共 39 行
JAVA
39 行
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;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?