struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henry F. Camacho Jr." <...@unpluggedcities.com>
Subject Re: [S2] Session Beans - how to make?
Date Sun, 27 May 2007 17:42:26 GMT
I create a session class that tracks all my session information needed 
for each user.  Since you will likely be in a action object when you 
want this information, you can do something like the following:

Here is my session object called SessionVars.

import javax.servlet.http.*;
public class SessionVars
{
    public SessionVars()
    {
   
    }
    public static void setUserID(HttpServletRequest request, Long userid)
    {
        request.getSession().setAttribute("user_id", (Long)userid);
    }
   
    public static Long getUserID(HttpServletRequest request)
    {
    Long work;
    work = (Long)request.getSession().getAttribute("user_id");

    if (work == null)
    {
        return(new Long(-1L));
    }
    else
    {
        return(work);
    }
    }

Now within a action you can perform something like this:

public class LogonForm extends ActionForm
{
protected String username;
protected String password;
   
    public LogonForm()
    {
    }
   
    public String getUsername() { return this.username; }
    public String getPassword() { return this.password; }
   
    public void setUsername(String un)    { this.username = un; }
    public void setPassword(String pw)    { this.password = pw; }
   
    public ActionErrors validate(ActionMapping mapping, 
HttpServletRequest request)
    {
        SessionVars.setUserID(request, useridhere);
    }
}
 



Mansour wrote:
> yitzle wrote:
>> Hi all.
>> I'm a Struts Newbie here, so I apologize for the stupid question ;)
>>
>> I'm working on making a fairly large Struts project.
>> Most data will be passed from one page/JSP to the next.
>> The login info has to be available on the server at every action.
>> How do I make a session bean or whatever that's seperate from the
>> other info that the action passes and is accessable for all the
>> actions?
>>
> You can store them in the session.
>
>> PS Also, how do I have one action() forward to another? Do I just set
>> the result to be second.action?
>>
> This is one way, called action chaining.
>> Thanks!
>>
>> ---------------------------------------------------------------------
>> 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
>

-- 
Henry F. Camacho Jr.
Unplugged Cities, LLC
800 Washington Ave No
Suite 501
Minneapolis, MN 55401
Fridley, MN  55432

763-235-3005 (Office)
763-257-6898 (Cell)
tknightowl (Skype)
hfc@unpluggedcities.com (email)
www.unpluggedcities.com (www)
KC0KUS (Amateur Radio)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message