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/29 18:25:35 UTC

[S2] Obtaining Session/Request Object

I want to store session information.
>From what I understand, the best way to do this is by accessing the
Session Object.
It appears I get the session by getting the Request Object
(HttpServletRequest or whatever) and calling its getSession().
Struts1 had execute() methods that took a Request as a parameter.
How do I get the Request in S2? What class can I implement that has an
execute() that gets a Request? Or is there a different way to do it?

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


Re: [S2] Obtaining Session/Request Object

Posted by yitzle <yi...@users.sourceforge.net>.
Oh. OK. That makes sense...
They have some sample code here [1] that made it "click" for me.
Thanks!
[1] http://www.infoq.com/articles/converting-struts-2-part1

On 5/29/07, Dave Newton <ne...@yahoo.com> wrote:
> --- yitzle <yi...@users.sourceforge.net144> wrote:
> > SessionAware only provides a setSession() method. No
> > getSession(). Do I use setSession both to set and
> get
> > Session variables?
>
> No, you use the map provided to the setSession method.
>
> d.

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


Re: [S2] Obtaining Session/Request Object

Posted by Dave Newton <ne...@yahoo.com>.
--- yitzle <yi...@users.sourceforge.net> wrote:
> SessionAware only provides a setSession() method. No
> getSession(). Do I use setSession both to set and
get 
> Session variables?

No, you use the map provided to the setSession method.

d.



       
____________________________________________________________________________________Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/

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


Re: [S2] Obtaining Session/Request Object

Posted by yitzle <yi...@users.sourceforge.net>.
SessionAware only provides a setSession() method. No getSession().
Do I use setSession both to set and get Session variables?

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


Re: [S2] Obtaining Session/Request Object

Posted by yitzle <yi...@users.sourceforge.net>.
The SessionAware documentation you linked me to earlier [1] states:
"This interface is only relevant if the Action is used in a servlet
environment."
So is SessionAware really ServletSessionAware and/or
ServletRequestAware the same as RequestAware?
(I'm not trying to equate two classes, but rather I'm trying to say
that either name would be correct.)

[1]http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/interceptor/SessionAware.html

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


RE: [OT] Re: [S2] Obtaining Session/Request Object

Posted by "Forsberg, Mike" <mi...@amd.com>.
First off, I think the notion of sighting wikipedia as the end all be
all of a definition is highly suspect.  After all, anyone can change the
Wikipedia at any time. For instance
http://en.wikipedia.org/wiki/The_Colbert_Report#_note-34

"On January 29, 2007, Colbert cited the case where Microsoft was alleged
to have hired someone [52] to tamper with Wikipedia..."

I like all the responses that Google has for define:servlet.  You may
want to quote one of them for your answer.

http://www.google.com/search?q=define:Servlet

This does sound a lot like a homework question or an interview question.

Hope I helped,

-----Original Message-----
From: anexpert@gmail.com [mailto:anexpert@gmail.com] On Behalf Of yitzle
Sent: Tuesday, May 29, 2007 4:29 PM
To: Struts Users Mailing List
Subject: Re: [OT] Re: [S2] Obtaining Session/Request Object

On 5/29/07, Dave Newton <ne...@yahoo.com> wrote:
> I'm starting to feel like we're doing your
> homework for you.
I'm sorry you feel that way.
If you prefer not to reply, its your prerogative.
I am just trying to understand the technology.

> A "Struts project" is not a servlet. A Struts project
> might *have* a servlet (and in S1 is pretty much
> guaranteed to have at least one), but in S2 they might
> be considered an anomaly.
"JSPs are compiled into Java Servlets by a JSP compiler. [1]"
The way I see it, so long as the result is a JSP page, the project
contains a servlet.
Granted, one can easily write the viewer component without JSP, but I
think its fair to guess that a large percentage of Struts projects
make use of JSP pages.

> A web application is any application that runs on the
> web, like a blog, or web email, or social site, or
> whatever.
A blog, web mail or social site that was written in Java and runs on
or inside a standard server such as Tomcat would be a servlet, though.
As far as I can tell, it meets all the requirements.
It sounds like, for any program (end point; excluding containers, such
as Tomcat, Struts, etc) accessed via a browser, if it is written in
Java, it is a servlet, otherwise its a web application.
How about a solid clear definition of a servlet?

[1] http://en.wikipedia.org/wiki/JavaServer_Pages

---------------------------------------------------------------------
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


Re: [OT] Re: [S2] Obtaining Session/Request Object

Posted by Dave Newton <ne...@yahoo.com>.
--- yitzle <yi...@users.sourceforge.net> wrote:
> "JSPs are compiled into Java Servlets by a JSP
> compiler. [1]" The way I see it, so long as the 
> result is a JSP page, the project contains a
servlet.

Semantics. 

The developer rarely, if ever, needs to care that a
JSP page is compiled into a servlet.

> A blog, web mail or social site that was written in
> Java and runs on or inside a standard server such as

> Tomcat would be a servlet, though.

You are incorrect. A blog, web mail, or social site
*may* contain *one or more* servlets. Or it may not.
As I said before.

> It sounds like, for any program (end point;
> excluding containers, such as Tomcat, Struts, etc) 

Struts is not a container.

> if it is written in Java, it is a servlet, otherwise

> its a web application.

You are incorrect. A servlet may be a single component
of a web application. Web applications do not *need*
to use servlets. For example, Struts 2, a member of
the Struts family this mailing list serves, does not
use servlets. A Struts 2 web application *may* use a
servlet. As I also said before, this is relatively
unusual.

> How about a solid clear definition of a servlet?

Servlets are classes that implement the Servlet
interface.

http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/Servlet.html

*Please* do basic JEE environment research somewhere
more appropriate: there are a *ton* of resources
available on the web that explain this in great
detail.

If you have Struts-related questions this is a great
place to get them answered. Other forums are more
appropriate for asking general JEE questions.

d.



 
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news

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


Re: [OT] Re: [S2] Obtaining Session/Request Object

Posted by yitzle <yi...@users.sourceforge.net>.
On 5/29/07, Dave Newton <ne...@yahoo.com> wrote:
> I'm starting to feel like we're doing your
> homework for you.
I'm sorry you feel that way.
If you prefer not to reply, its your prerogative.
I am just trying to understand the technology.

> A "Struts project" is not a servlet. A Struts project
> might *have* a servlet (and in S1 is pretty much
> guaranteed to have at least one), but in S2 they might
> be considered an anomaly.
"JSPs are compiled into Java Servlets by a JSP compiler. [1]"
The way I see it, so long as the result is a JSP page, the project
contains a servlet.
Granted, one can easily write the viewer component without JSP, but I
think its fair to guess that a large percentage of Struts projects
make use of JSP pages.

> A web application is any application that runs on the
> web, like a blog, or web email, or social site, or
> whatever.
A blog, web mail or social site that was written in Java and runs on
or inside a standard server such as Tomcat would be a servlet, though.
As far as I can tell, it meets all the requirements.
It sounds like, for any program (end point; excluding containers, such
as Tomcat, Struts, etc) accessed via a browser, if it is written in
Java, it is a servlet, otherwise its a web application.
How about a solid clear definition of a servlet?

[1] http://en.wikipedia.org/wiki/JavaServer_Pages

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


[OT] Re: [S2] Obtaining Session/Request Object

Posted by Dave Newton <ne...@yahoo.com>.
--- yitzle <yi...@users.sourceforge.net> wrote:
> So, it would seem a Strut project is a servlet. It 
> runs inside the web container, receives an HTTP 
> request, generates and sends an HTTP response. Meets

> all the criteria. Right? Now, how do you define a
web
> application?

You may wish to seek elsewhere for non-Struts related
questions. I'm starting to feel like we're doing your
homework for you.

A "Struts project" is not a servlet. A Struts project
might *have* a servlet (and in S1 is pretty much
guaranteed to have at least one), but in S2 they might
be considered an anomaly.

A web application is any application that runs on the
web, like a blog, or web email, or social site, or
whatever.

d.



       
____________________________________________________________________________________Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting 

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


Re: [S2] Obtaining Session/Request Object

Posted by yitzle <yi...@users.sourceforge.net>.
Alright. Read that page. Wikipedia's definition needs updating.
What I understand from that is that a servlet is basically like a Java
CGI program that runs in the web server process. So, it would seem a
Strut project is a servlet. It runs inside the web container, receives
an HTTP request, generates and sends an HTTP response. Meets all the
criteria. Right?
Now, how do you define a web application?

On 5/29/07, Al Sutton <al...@al-and-andrea.org.uk> wrote:
> Maybe you should start with;
>
> http://java.sun.com/products/servlet/articles/tutorial/
>
> Instead of wikipedia or the struts documentation.
>
> When you've got a grasp of what servlets and webapps are, then it might be
> time to re-visit struts.

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


RE: [S2] Obtaining Session/Request Object

Posted by Al Sutton <al...@al-and-andrea.org.uk>.
Maybe you should start with;

http://java.sun.com/products/servlet/articles/tutorial/

Instead of wikipedia or the struts documentation.

When you've got a grasp of what servlets and webapps are, then it might be
time to re-visit struts.

-----Original Message-----
From: anexpert@gmail.com [mailto:anexpert@gmail.com] On Behalf Of yitzle
Sent: 29 May 2007 18:57
To: Struts Users Mailing List
Subject: Re: [S2] Obtaining Session/Request Object

On 5/29/07, Dave Newton <ne...@yahoo.com> wrote:
> --- yitzle <yi...@users.sourceforge.net53> wrote:
> > Now I need to figure out what classifies a Servlet vs a Web 
> > Application.
>
> Er...
>
> In case you're serious, a servlet is part of a web application.
>
> d.

Let me see if I get this...
According to Wikipedia: "A Servlet is an object that receives a request
(ServletRequest) and generates a response (ServletResponse) based on the
request. [1]"
Shouldn't that make a web server a servlet? Or must it be a Java Object?
Tomcat is a web application.
Struts2 is a framework. It basically provides a bunch of pre-built classes
and interfaces, and allows a MVC setup. The controller gets the request. The
model does some business logic and the viewer generates a response. The
viewer uses JSP, and JSPs are turned into servlets.
Is the model a web application? A web servlet? Or just a normal Java Object
(POJO?) that I need to make SessionAware?

[1] http://en.wikipedia.org/wiki/Servlet

---------------------------------------------------------------------
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


Re: [S2] Obtaining Session/Request Object

Posted by yitzle <yi...@users.sourceforge.net>.
On 5/29/07, Dave Newton <ne...@yahoo.com> wrote:
> --- yitzle <yi...@users.sourceforge.net53> wrote:
> > Now I need to figure out what classifies a Servlet
> > vs a Web Application.
>
> Er...
>
> In case you're serious, a servlet is part of a web
> application.
>
> d.

Let me see if I get this...
According to Wikipedia: "A Servlet is an object that receives a
request (ServletRequest) and generates a response (ServletResponse)
based on the request. [1]"
Shouldn't that make a web server a servlet? Or must it be a Java Object?
Tomcat is a web application.
Struts2 is a framework. It basically provides a bunch of pre-built
classes and interfaces, and allows a MVC setup. The controller gets
the request. The model does some business logic and the viewer
generates a response. The viewer uses JSP, and JSPs are turned into
servlets.
Is the model a web application? A web servlet? Or just a normal Java
Object (POJO?) that I need to make SessionAware?

[1] http://en.wikipedia.org/wiki/Servlet

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


Re: [S2] Obtaining Session/Request Object

Posted by Dave Newton <ne...@yahoo.com>.
--- yitzle <yi...@users.sourceforge.net> wrote:
> Now I need to figure out what classifies a Servlet
> vs a Web Application.

Er...

In case you're serious, a servlet is part of a web
application.

d.



       
____________________________________________________________________________________Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC

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


Re: [S2] Obtaining Session/Request Object

Posted by yitzle <yi...@users.sourceforge.net>.
Now I need to figure out what classifies a Servlet vs a Web Application.
Wikipedia should be of use...

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


Re: [S2] Obtaining Session/Request Object

Posted by Martin Gainty <mg...@hotmail.com>.
dave is right..
feel free to ask this on tomcat users group
users@tomcat.apache.org

M--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Dave Newton" <ne...@yahoo.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, May 29, 2007 1:03 PM
Subject: Re: [S2] Obtaining Session/Request Object


> --- yitzle <yi...@users.sourceforge.net> wrote:
>> ... unless I am writing a Servlet.
>
> In which case it isn't an S2 question at all and
> should be asked elsewhere, and the previous
> sub-optimal solution would also be incorrect.
>
> d.
>
>
>
>
> ____________________________________________________________________________________Yahoo! 
> oneSearch: Finally, mobile search
> that gives answers, not web links.
> http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
>
> ---------------------------------------------------------------------
> 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


Re: [S2] Obtaining Session/Request Object

Posted by Dave Newton <ne...@yahoo.com>.
--- yitzle <yi...@users.sourceforge.net> wrote:
> ... unless I am writing a Servlet.

In which case it isn't an S2 question at all and
should be asked elsewhere, and the previous
sub-optimal solution would also be incorrect.

d.



       
____________________________________________________________________________________Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC

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


Re: [S2] Obtaining Session/Request Object

Posted by yitzle <yi...@users.sourceforge.net>.
> No, you should implement SessionAware
> http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/interceptor/SessionAware.html55
> and avoid being tied to the Servlet spec.

... unless I am writing a Servlet.

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


Re: [S2] Obtaining Session/Request Object

Posted by Dave Newton <ne...@yahoo.com>.
--- Yoni Amir <am...@gmail.com> wrote:
> Your action should implement the ServletRequestAware
> interface, then the Servlet Config Interceptor,
which
> is active by default, does the rest.
>
http://struts.apache.org/2.x/docs/servlet-config-interceptor.html

No, you should implement SessionAware

http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/interceptor/SessionAware.html

and avoid being tied to the Servlet spec.

d.



      ____________________________________________________________________________________Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 


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


Re: [S2] Obtaining Session/Request Object

Posted by Yoni Amir <am...@gmail.com>.
Your action should implement the ServletRequestAware interface, then
the Servlet Config Interceptor, which is active by default, does the
rest.

http://struts.apache.org/2.x/docs/servlet-config-interceptor.html

Yoni

On 5/29/07, yitzle <yi...@users.sourceforge.net> wrote:
> I want to store session information.
> From what I understand, the best way to do this is by accessing the
> Session Object.
> It appears I get the session by getting the Request Object
> (HttpServletRequest or whatever) and calling its getSession().
> Struts1 had execute() methods that took a Request as a parameter.
> How do I get the Request in S2? What class can I implement that has an
> execute() that gets a Request? Or is there a different way to do it?
>
> ---------------------------------------------------------------------
> 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