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 17:04:51 GMT

By implementing the interfaces I will have access to Request and session
objects in action class alone or also in the jsp's and that too in struts2
tags only and not using scriptlets? 

To make it more clear will 
<s:property value="#request['abc']"/>  print "xyz" if the url for the page
was *.action?abc=xyz
Is the syntax that I used correct for accessing the request parameter called
"abc" with value "xyz". 
I am trying to do something like this but not able to succeed.

Will implementing RequestAware interface in the action class make the above
work and xyz be printed??
Also see if you can help me out with the last two issues that I mentioned in
the first post.
 

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

-- 
View this message in context: http://www.nabble.com/How-to-access-request---session-objects-in-jsp-using-struts2-tags-tf4354438.html#a12411676
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