struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From afp <arup.fran...@bankofamerica.com>
Subject Re: How to access request & session objects in jsp using struts2 tags
Date Thu, 30 Aug 2007 16:55:15 GMT

I guess I could do that by having a flag for that in the action and then
using that in the jsp but really tat doesn't quite answer the question. In
general how do we access the request or session in the jsp?

Will what I have given below work or what shud I be doing to make it work!

Is it that I have to implement the sessionaware and requestaware interfaces
in the action to be accessing the session and request in jsp? I am already
doing this and am getting the session object in the action? Will the request
and session available in the jsp as shown in my code below only if the above
interfaces are implemented by the action class? The requirement is tat I
need to access it in the jsp and not in the action class method. 



newton.dave wrote:
> 
>> On 8/30/07, afp wrote:
>>> I am trying to identify whether a button has
>>> been clicked or not in my **jsp**.
> 
> Emphasis mine.
> 
> The real question is why is that being done in the JSP
> directly from the request parameters when it would
> probably be better to set a flag based on whatever
> business logic might be happening or access the value
> from an action property or determine if the
> submission-based differences could be better isolated
> with an application resource or different result, etc.
> 
> --- Chris Pratt <thechrispratt@gmail.com> wrote:
> 
>> If you just need access to the Request Attributes,
>> try implementing
>> RequestAware in your action.  If you need access to
>> other, more
>> Servlet specific, parts of the Request, you'll have
>> tto implement
>> ServletRequestAware.  Similarly for Sessions, if you
>> just need the
>> attributes, implement SessionAware, if you need full
>> access implement
>> ServletRequestAware and call request.getSession().
>>   (*Chris*)
>> 
>> On 8/30/07, afp <arup.francis@bankofamerica.com>
>> wrote:
>> >
>> > Hi,
>> >
>> >    I am trying to identify whether a button has
>> been clicked or not in my
>> > jsp.
>> > The way I do this or is trying to do this is to
>> access the request object
>> > and then check in that for the button name. The
>> code is as shown below
>> >
>> > The button which was clicked is coded as shown
>> below
>> > <s:submit value="Continue"
>> action="InitAction_stub" type="image"
>> > title="Continue" />
>> >
>> > The piece of code where I am trying to check for
>> the button in the jsp
>> > <s:if test="#request['action:InitAction_stub.x']
>> != null">
>> >         HI
>> >         <s:set name="abc.currentDisplaySection"
>> value="%{'All'}" />
>> >         <%
>> request.setAttribute("currentSection","All"); %>
>> > </s:if>
>> > <s:else>
>> >         <%
>> request.setAttribute("currentSection","no"); %>
>> > </s:else>
>> >
>> > Now I know that the parameter
>> "action:InitAction_stub.x" is present in the
>> > request Map as I can see that in the Action class
>> which later forwards to
>> > the jsp. But I am unable to access it in the jsp.
>> >
>> > Is the way I am trying to access the request
>> parameter wrong?
>> > If so how do I get a request parameter in the jsp
>> - I saw the following
>> > usage in one of the struts2 pages
>> >
>> > <s:property
>> value="#request['action:InitAction_stub.x']"/> this
>> shud ideally
>> > print out the value of the button or any other
>> request parameter. But
>> > nothing gets printed. So where am I going wrong
>> and what do I need to do?
>> >
>> > Also along with this is there any way I can do the
>> below without using
>> > scriptlets
>> > <% request.setAttribute("currentSection","All");
>> %>
>> >
>> > Also say I have an object in my action class will
>> I be able to rewrite the
>> > value of that object by using the set statement
>> i.e. will <s:set
>> > name="abc.currentDisplaySection" value="%{'All'}"
>> /> where abc is an object
>> > which is specified in the action class and has
>> getters and setters. My doubt
>> > is whether the above statement will update the
>> currentDisplaySection
>> > variable under abc object?? so that if I say print
>> out the value later using
>> > a <s:property value="abc.currentDisplaySection"/>
>> it shud print out 'All".
>> > Will this work??
>> >
>> >
>> > TIA,
>> > Arup
>> > --
>> > View this message in context:
>>
> http://www.nabble.com/How-to-access-request---session-objects-in-jsp-using-struts2-tags-tf4354438.html#a12407850
>> > Sent from the Struts - User mailing list archive
>> at Nabble.com.
>> >
>> >
>> >
>>
> ---------------------------------------------------------------------
>> > 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
>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
;-);-);-)
-- 
View this message in context: http://www.nabble.com/How-to-access-request---session-objects-in-jsp-using-struts2-tags-tf4354438.html#a12411552
Sent from the Struts - User mailing list archive at Nabble.com.


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


Mime
View raw message