Thanks for any help,
schmen
Take a look at the javadocs for RequestProcessor and note those methods
which return a boolean. The return value indicates whether or not to
continue processing the request. In my processPreprocess method I can
examine the session context and decide whether or not the user has
logged-in to the application. If so then I simply return true. Else I
can invoke doForward and return false.
Sorry I don't have a URL I can point you to...
Thanks for your help, I am still having problems and I think that it
would be helpful if you were to provide the code snipit that calls the
.doForward() method within the RequestProcessor class, as well as your
<forward> entry definition within your struts-config file.
Thanks again.
I have two objections: I don't like to waste other people's bandwidth,
and I usually charge money for delivering this kind of code. That said,
I'll make an exception so that this can end up in the archives and
might assist others in the future.
I use a global forward for my login, the page I redirect users to when
they don't have credentials in session scope. Here's some snippets from
struts-config.xml:
<global-forwards>
<forward name="login" path="/login"/>
</global-forwards>
<action-mappings>
<action name="loginForm"
path="/login"
type="com.onlinetrs.trs.LoginAction"
scope="request"
validate="true"
input="/WEB-INF/jsp/login.jsp">
<forward name="continue" path="/index.jsp"/>
</action>
</action-mappings>
<controller
contentType="text/html;charset=UTF-8"
debug="0"
nocache="true"
processorClass="com.onlinetrs.trs.MyRequestProcessor"/>
Here's the code for MyRequestProcessor:
package com.onlinetrs.trs;
import org.apache.struts.action.RequestProcessor;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.ForwardConfig;
import org.apache.struts.action.ActionMapping;
import org.apache.commons.logging.Log;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletException;
import java.io.IOException;
public class MyRequestProcessor extends RequestProcessor {
private static final String loginPath = "/login";
public boolean processPreprocess( HttpServletRequest req,
HttpServletResponse resp ) {
HttpSession sess = req.getSession( true );
Integer userID = (Integer) sess.getAttribute( "user" );
String requestPath = null;
String forwardPath = null;
ActionMapping loginActionMapping = null;
boolean rc = false;
/*
* if userID in session then already logged-in
*/
if( userID != null )
return( true );
/*
* get the request path
*/
try {
requestPath = processPath( req, resp );
}
catch( IOException e ) {
log.error( e.toString() );
return( true );
}
/*
* if it's login then continue
*/
if( requestPath.equals( loginPath ) )
return( true );
/*
* save the original request
*/
sess.setAttribute( "originalRequest", requestPath );
/*
* get the action for the login
*/
try {
loginActionMapping = processMapping( req, resp,
loginPath );
forwardPath =
loginActionMapping.getInputForward().getPath();
doForward( forwardPath, req, resp );
return( false );
}
catch( Exception e ) {
log.error( e.toString() );
return( true );
}
}
}
Fair enough?
Thanks a lot!
Sudsy <bitbu...@hotmail.com> wrote in message news:<402E763...@hotmail.com>...
More points, before somebody else "jumps the gun":
- don't top post
- trim the reply
ps. Send money!