I just tried (and failed) using a fully qualified URL as the ActionForward.  The 
exception told me that my path did not start with a /

So.... here is an action that will use a redirect instead of an ActionForward.  This 
works:


/**
 * a simple action to invalidate a session and return
 * the user to the home page
 */
public class LogoffAction extends Action {

    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response){

                request.getSession().invalidate();
            ActionForward foward = mapping.findForward("home");
            String path = forward.getPath();
            response.sendRedirect(path);
            return null;
    }
}



the corresponding struts-config entry....

<global-forwards>
        <forward name="home" path="http://www.mysite.com"; />
</global-forwards>


NOTE!!!!!

when you retrieve this ActionForward through the ActionMapping object, it will FAIL if 
you try to return it from the execute() method.  It fails because a fully qualified 
URL won't work in the ActionForward.

You can use the Forward "home" to store the fully-qualified URL (and retrieve it via 
forward.getPath()) or you can put that in some other property section or config file.  
Either way, you can use response.sendRedirect(str) to send the user to any website you 
wish, including your own home page.

I hope this helps.

mark


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 22, 2003 2:28 PM
To: [EMAIL PROTECTED]
Subject: RE: accessing static html from struts-config.xml


No the reference to the path in the <forward> section does not work.
I am not sure how to use the response.redirect method. Do we put this
method in the execute method of the LogoffAction? or do we make a new
method called public void redirect(HttpServletRequest....){
response.redirect("http://localhost/xyz.html";);
}


> I believe that you are not forced to use a relative URL.  You can put
> "http://www.mysite.com/index.html"; as the Forward path and it should
> work just fine.
>
> If, for whatever reason, the Forward to an absolute URL does not work,
> you can always use
>
> response.redirect(actionForward.getPath())
>
> in your Action while returning a null ActionForward
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, October 22, 2003 12:58 PM
> To: [EMAIL PROTECTED]
> Subject: accessing static html from struts-config.xml
>
>
> Hi All
> I am trying to do a logoff action.When the user logsoff he should be
> taken to the main website which is under /var/www/html/blah/index.shtml
> which is completely out of the tomcat and this is where i have stored
> the static content of the website.
> I do not understand how to write this forward in my struts-config.xml
> <forward name="xyzhome" path="../blah.shtml" /> does not do anything or
> can i specify a URI to access the resource.
>
> Thanx
> --Mohan
>
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: [EMAIL PROTECTED] For
> additional commands, e-mail: [EMAIL PROTECTED]
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: [EMAIL PROTECTED] For
> additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to