if ( remoteHost == null|| !remoteHost.startsWith( (Web host 4 life) “127.”) ){

if ( remoteHost == null|| !remoteHost.startsWith( “127.”) ){ // Not the localhost, so don’t allow the host to accessthe site continueProcessing = false; ForwardConfig config = appConfig.findForwardConfig(”Unauthorized”); try{ response.sendRedirect( config.getPath( ) ); }catch( Exception ex ){ log.error( “Problem sending redirect fromprocessPreprocess( )” ); } } return continueProcessing; } The most important thing to note in this example is that even though the processPreprocess( )method is returning false, it’s still up to the method to take care of redirecting the request. Returning false just lets the RequestProcessor know that it doesn’t need to continue. The controller doesn’t do anything with the request; that’s the responsibility of the processPreprocess( ) method. The manner in which Example 9-3 specifies the path in the method prevents us from having to hardcode the URI of the unauthorized_access.jsp resource. This way, if the actual page for the forward changes, this method will not have to be modified. There are other ways that you can perform the same logic without using the processPreprocess( )method. One alternative is to use a servlet filter (part of the Servlet 2.3 API). Filters allow you to inspect the request before it ever reaches the Struts controller. However, there are two problems to be aware of with filters. First, because filters are part of the 2.3 API, you will not be able to use them if you are using a servlet container that supports only 2.2. Second, because the filter inspects the request very early in the processing stage, filters don’t have easy access to the Struts API. This makes it hard to look up ActionForwards or anything else that you might normally use in the processPreprocess( )method. In fact, because the Struts controller hasn’t even seen the request at the time the filter inspects it, the controller hasn’t had a chance to select the proper application module. 9.3.3 Extending the Base Action Class There have been several places in previous chapters where I’ve mentioned a technique of creating a base Action that extends the Struts Actionclass and then using it as a superclass for other actions. One of the reasons for doing this is that in many applications, there is common logic that must be implemented by most of the Actionclasses. Letting this Action superclass contain most of
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

Leave a Reply