You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alex Colic <al...@pop-ware.com> on 2001/12/07 14:45:26 UTC

RE: Can't forward to a global-Here's the code in question?

Here the action class, slightly abbreviated.

package com.popware.rd.viPro.action;


public class viInvoiceSummaryAction extends Action
{

  private static final Category
cat=Category.getInstance(viInvoiceSummaryAction.class.getName());
  private HttpSession session;
  private ActionErrors errors=new ActionErrors();
  private ActionMessages messages=new ActionMessages();

  public ActionForward perform( ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response)
                                throws java.io.IOException,
javax.servlet.ServletException
  {
    errors.clear();
    messages.clear();

    session=request.getSession();
    if(session == null || session.isNew()) return
(mapping.findForward("logon"));

    Vector v=new Vector();
    v=getInvoiceSummary();

   if(messages.empty())
      {
        if((v.size()>0) && (v!=null))
          {
            request.setAttribute("invoiceSummary",v);
          }
      }

   if(!errors.empty())
    {
      this.saveErrors(request,errors);
      return (new ActionForward(mapping.getInput()));
    }

    if(mapping.getAttribute()!=null)
      if("request".equals(mapping.getScope()))
        {
          request.removeAttribute(mapping.getAttribute());
        }
      return (mapping.findForward("success"));
  }
}

I can see the logon page loading and then the rest of this classes code gets
executed.

Thanks for any help.

Alex
-----Original Message-----
From: Tom Klaasen (TeleRelay) [mailto:tom.klaasen@telerelay.com]
Sent: Friday, December 07, 2001 4:30 AM
To: Struts Users Mailing List
Subject: RE: Can't forward to a global?




> -----Original Message-----
> From: Alex Colic [mailto:alex.colic@pop-ware.com]
> Sent: donderdag 6 december 2001 22:06
> To: Struts
> Subject: Can't forward to a global?
>
>
>
> Hi,
>
> I have an action class that could get called after a users session has
> expired. When the action class is called I have the following code:
>
>     if(session == null || session.isNew())
>         {
>           return mapping.findForward("logon");
>         }
> I have a global forward defined for "logon."
>
> Now the problem:
>
> When a user's session is expired and the click a link they go to this
> action. The if statement evaluates to true and the forward to "logon"
> correctly occurs. Then the rest of the Action code continues to be
> evaluated.
>
> Why is the rest of my code following the above if statement
> continuing to be
> run when I have done a forward?

Are you absolutely sure about this? No other people on your server who
could generate the same debug code as you? Because I don't expect the
code to continue: the return ...; statement jumps out of the method.

hth,
tomK


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Can't forward to a global-Here's the code in question?

Posted by Keith Bacon <ke...@yahoo.com>.
Alex,
I haven't got the docs to hand but I think
request.getSession();
creates a session if there isn't one - ie. can never
return null. Also I think struts might be creating the
session before calling your perform method.
Maybe you want to test for some object that your
application puts in the session - maybe  the user
details.
hth,
Keith.

--- Alex Colic <al...@pop-ware.com> wrote:
> Here the action class, slightly abbreviated.
> 
> package com.popware.rd.viPro.action;
> 
> 
> public class viInvoiceSummaryAction extends Action
> {
> 
>   private static final Category
>
cat=Category.getInstance(viInvoiceSummaryAction.class.getName());
>   private HttpSession session;
>   private ActionErrors errors=new ActionErrors();
>   private ActionMessages messages=new
> ActionMessages();
> 
>   public ActionForward perform( ActionMapping
> mapping,
>                                 ActionForm form,
>                                 HttpServletRequest
> request,
>                                 HttpServletResponse
> response)
>                                 throws
> java.io.IOException,
> javax.servlet.ServletException
>   {
>     errors.clear();
>     messages.clear();
> 
>     session=request.getSession();
>     if(session == null || session.isNew()) return
> (mapping.findForward("logon"));
> 
>     Vector v=new Vector();
>     v=getInvoiceSummary();
> 
>    if(messages.empty())
>       {
>         if((v.size()>0) && (v!=null))
>           {
>            
> request.setAttribute("invoiceSummary",v);
>           }
>       }
> 
>    if(!errors.empty())
>     {
>       this.saveErrors(request,errors);
>       return (new
> ActionForward(mapping.getInput()));
>     }
> 
>     if(mapping.getAttribute()!=null)
>       if("request".equals(mapping.getScope()))
>         {
>          
> request.removeAttribute(mapping.getAttribute());
>         }
>       return (mapping.findForward("success"));
>   }
> }
> 
> I can see the logon page loading and then the rest
> of this classes code gets
> executed.
> 
> Thanks for any help.
> 
> Alex
> -----Original Message-----
> From: Tom Klaasen (TeleRelay)
> [mailto:tom.klaasen@telerelay.com]
> Sent: Friday, December 07, 2001 4:30 AM
> To: Struts Users Mailing List
> Subject: RE: Can't forward to a global?
> 
> 
> 
> 
> > -----Original Message-----
> > From: Alex Colic [mailto:alex.colic@pop-ware.com]
> > Sent: donderdag 6 december 2001 22:06
> > To: Struts
> > Subject: Can't forward to a global?
> >
> >
> >
> > Hi,
> >
> > I have an action class that could get called after
> a users session has
> > expired. When the action class is called I have
> the following code:
> >
> >     if(session == null || session.isNew())
> >         {
> >           return mapping.findForward("logon");
> >         }
> > I have a global forward defined for "logon."
> >
> > Now the problem:
> >
> > When a user's session is expired and the click a
> link they go to this
> > action. The if statement evaluates to true and the
> forward to "logon"
> > correctly occurs. Then the rest of the Action code
> continues to be
> > evaluated.
> >
> > Why is the rest of my code following the above if
> statement
> > continuing to be
> > run when I have done a forward?
> 
> Are you absolutely sure about this? No other people
> on your server who
> could generate the same debug code as you? Because I
> don't expect the
> code to continue: the return ...; statement jumps
> out of the method.
> 
> hth,
> tomK
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>