You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Kennedy <da...@swanlabs.com> on 2005/03/20 15:25:02 UTC
How to call a Struts 'forward' from a CustomRequestProcessor?
Easy one for a Sunday morning:
I'm got a simple CustomRequestProcessor which checks for the presence of
a user login bean, and if not found, it should bounce the request to my
logon page.
Problem: how can I say "Go to the Struts Forward /logon" from within the
CustomRequestProcessor?
Bonus points: how can I stop the browser's 'Back' key letting the user
cheat...
protected boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response)
{
final HttpSession session = request.getSession(false);
final Logger log = Logger.getLogger(this.getClass());
final String path = request.getServletPath();
if (path.equals("/logon") || path.equals("/logon.do"))
{
return true;
}
if (session != null
&&
session.getAttribute(ApplicationAttributes.USER_KEY) != null)
{
if (log.isDebugEnabled())
{
log.debug("User bean located in session. Permitting
request...");
}
return true;
}
else
{
if (log.isDebugEnabled())
{
log.debug("No user bean located in session. Refusing
request and forwarding to logon...");
}
try
{
// ***************************************
// ***************************************
// ** HOW CAN I MAKE THIS CALL A STRUTS **
// ** FORWARD CALLED '/logon' INSTEAD? **
// ***************************************
// ***************************************
request.getRequestDispatcher(
"/logon/logon.jsp").forward(request, response);
}
catch(Exception e)
{
log.error("Unable to forward to /logon",e);
}
}
return false;
}
--
David Kennedy
Swan Labs
http://www.swanlabs.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to call a Struts 'forward' from a CustomRequestProcessor?
Posted by David Kennedy <da...@swanlabs.com>.
Mike Deegan wrote:
[snip]
> import org.apache.struts.config.ForwardConfig;
> {
> ForwardConfig fc =
> mapping.getModuleConfig().findForwardConfig("unauthorized");
^^^^^^^^^^^
> request.getRequestDispatcher(fc.getPath()).forward(request,response);
> }
Thanks, my problem with this is that processPreprocess() doesn't have an
ActionMapping parameter, so I guess what I should have asked was, "How
can I make an ActionMapping?" However, I'm now thinking, "I was tired
earlier and should just have overridden processRoles() and not
processPreprocess()"!
> ----- Original Message ----- From: "David Kennedy"
> <da...@swanlabs.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Sunday, March 20, 2005 7:25 AM
> Subject: How to call a Struts 'forward' from a CustomRequestProcessor?
>
>
>> Easy one for a Sunday morning:
>> I'm got a simple CustomRequestProcessor which checks for the presence
>> of a user login bean, and if not found, it should bounce the request
>> to my logon page.
>>
>> Problem: how can I say "Go to the Struts Forward /logon" from within
>> the CustomRequestProcessor?
>> Bonus points: how can I stop the browser's 'Back' key letting the user
>> cheat...
>>
>> protected boolean processPreprocess(HttpServletRequest request,
>> HttpServletResponse response)
>> {
>> final HttpSession session = request.getSession(false);
>> final Logger log = Logger.getLogger(this.getClass());
>> final String path = request.getServletPath();
>> if (path.equals("/logon") || path.equals("/logon.do"))
>> {
>> return true;
>> }
>> if (session != null
>> &&
>> session.getAttribute(ApplicationAttributes.USER_KEY) != null)
>> {
>> if (log.isDebugEnabled())
>> {
>> log.debug("User bean located in session. Permitting
>> request...");
>> }
>> return true;
>> }
>> else
>> {
>> if (log.isDebugEnabled())
>> {
>> log.debug("No user bean located in session. Refusing
>> request and forwarding to logon...");
>> }
>> try
>> {
>> // ***************************************
>> // ***************************************
>> // ** HOW CAN I MAKE THIS CALL A STRUTS **
>> // ** FORWARD CALLED '/logon' INSTEAD? **
>> // ***************************************
>> // ***************************************
>> request.getRequestDispatcher(
>> "/logon/logon.jsp").forward(request, response);
>> }
>> catch(Exception e)
>> {
>> log.error("Unable to forward to /logon",e);
>> }
>> }
>> return false;
>> }
>>
>>
>>
>> --
>> David Kennedy
>> Swan Labs
>> http://www.swanlabs.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
--
David Kennedy
Swan Labs
http://www.swanlabs.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to call a Struts 'forward' from a CustomRequestProcessor?
Posted by Mike Deegan <mp...@hotmail.com>.
Googled and found this snippet that my help!
http://technology.amis.nl/blog/index.php?p=400
Comment by Leon van Tegelen - 14/2/2005 @ 11:17 pm
The actual way to do it would be to forward to a global forward named
"unauthorized" in the struts-config, like so
import org.apache.struts.config.ForwardConfig;
{
ForwardConfig fc =
mapping.getModuleConfig().findForwardConfig("unauthorized");
request.getRequestDispatcher(fc.getPath()).forward(request,response);
}
----- Original Message -----
From: "David Kennedy" <da...@swanlabs.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Sunday, March 20, 2005 7:25 AM
Subject: How to call a Struts 'forward' from a CustomRequestProcessor?
> Easy one for a Sunday morning:
> I'm got a simple CustomRequestProcessor which checks for the presence of a
> user login bean, and if not found, it should bounce the request to my
> logon page.
>
> Problem: how can I say "Go to the Struts Forward /logon" from within the
> CustomRequestProcessor?
> Bonus points: how can I stop the browser's 'Back' key letting the user
> cheat...
>
> protected boolean processPreprocess(HttpServletRequest request,
> HttpServletResponse response)
> {
> final HttpSession session = request.getSession(false);
> final Logger log = Logger.getLogger(this.getClass());
> final String path = request.getServletPath();
> if (path.equals("/logon") || path.equals("/logon.do"))
> {
> return true;
> }
> if (session != null
> &&
> session.getAttribute(ApplicationAttributes.USER_KEY) != null)
> {
> if (log.isDebugEnabled())
> {
> log.debug("User bean located in session. Permitting
> request...");
> }
> return true;
> }
> else
> {
> if (log.isDebugEnabled())
> {
> log.debug("No user bean located in session. Refusing
> request and forwarding to logon...");
> }
> try
> {
> // ***************************************
> // ***************************************
> // ** HOW CAN I MAKE THIS CALL A STRUTS **
> // ** FORWARD CALLED '/logon' INSTEAD? **
> // ***************************************
> // ***************************************
> request.getRequestDispatcher(
> "/logon/logon.jsp").forward(request, response);
> }
> catch(Exception e)
> {
> log.error("Unable to forward to /logon",e);
> }
> }
> return false;
> }
>
>
>
> --
> David Kennedy
> Swan Labs
> http://www.swanlabs.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org