You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by yitzle <yi...@users.sourceforge.net> on 2007/05/27 05:43:31 UTC
[S2] Session Beans - how to make?
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?
PS Also, how do I have one action() forward to another? Do I just set
the result to be second.action?
Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] Session Beans - how to make?
Posted by Isaac Good <is...@rentmagic.ca>.
Thanks for the reply.
It appears your solution is for Struts1, not Struts2.
On 5/27/07, Henry F. Camacho Jr. <hf...@unpluggedcities.com> wrote:
> 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);
> }
> }
>
> --
> 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.com58 (email)
> www.unpluggedcities.com59 (www)
> KC0KUS (Amateur Radio)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] Session Beans - how to make?
Posted by "Henry F. Camacho Jr." <hf...@unpluggedcities.com>.
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
Re: [S2] Session Beans - how to make?
Posted by Mansour <ma...@yahoo.com>.
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