You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by afp <ar...@bankofamerica.com> on 2007/08/30 16:00:18 UTC

How to access request & session objects in jsp using struts2 tags

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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Gurpreet-Singh <ig...@gmail.com>.
Hi All,

I am developing WML application using struts2 and tiles on weblogic server
10. 
Struts2 version: 2.0.11

I am facing 2 problems:

1. I am generating a url to the external site using <s:a> and <s:url> as
follows:
<s:url id="externalURL" value="http://localhost:8080/test" encode="true">
 <s:param name="returnURL" value='%{request.getHeader("Referer")}" />
</s:url>
<s:a id="Go" href="%{externalURL}" > Go to Another Application Server page
</s:a>

Basically, I want to go to external site running on another app server and
appending returnURL parameter which will be used on the exernal site to come
back to this web application page running on different server.

e.g returnURL contains: http://localhost:7001/demo/index.action?id=123

so the expected URL generation is:
http://localhost:8080/test?returnURL=http://localhost:7001/demo/index.action?id=123

But when i am checking the page source, it shows the %20D, %20F which means
its converting the : / & character exist in returnURL parameter value. 

Please give your suggesstion to resolve this problem. Also, let me know is
this ok to generate url to external site to ensure we can come back to the
value of returnURL parameter.

2. The situation is like same as above problem as follows:

Web App1 - Page 1 - Go Link points to Page 2 with returnURL parameter points
to "Referer" value.
Web App2 - Page 2 - Go back link points to value of return URL i.e. Page 1

Both Web App1 and 2 are running on different server.

Page 1 has the link generation code mentioned in the problem 1. When i click
on 'Go to Another Application Server page ' link, it takes me successfully
to Page 2. Now, i am clicking on Go back link which contains href property
set to returnURL parameter value to come back to Page 1.

Problem is that when i am coming back to page 1 from page 2, its errors out.
But error goes offf if i hit refresh or opens this page in a new window. So,
is it due to switching context between 2 web server in the same browser
window or what?

~Gurpreet Singh



Arup Francis 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-tp12407850p19683003.html
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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Alexander Baetz <ba...@arcor.de>.
Gurpreet-Singh schrieb:
> Hi All,
>
> I am developing WML application using struts2 and tiles on weblogic server
> 10. 
> Struts2 version: 2.0.11
>
> I am facing 2 problems:
>
> 1. I am generating a url to the external site using <s:a> and <s:url> as
> follows:
> <s:url id="externlaURL" value="http://localhost:8080/test" encode="true">
>  <s:param name="returnURL" value='%{request.getHeader("Referer")}" />
> </s:url>
> <s:a id="Go" href="%{externalURL}" > Go to Another Application Server page
> </s:a>
Maybe you can workaround this problem by rewriting the parameter linke this:

 <s:param name="returnURL" ><s:property value="#request.Header("Referer")" /></s:param>

Just a guess.
> 2. The situation is like same as above problem as follows:
> ...
> Problem is that when i am coming back to page 1 from page 2, its errors out.
> But error goes offf if i hit refresh or opens this page in a new window. So,
> is it due to switching context between 2 web server in the same browser
> window or what?
What errors do you get?

Greetings,
Alexander

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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Gurpreet-Singh <ig...@gmail.com>.
Hi All,

I am developing WML application using struts2 and tiles on weblogic server
10. 
Struts2 version: 2.0.11

I am facing 2 problems:

1. I am generating a url to the external site using <s:a> and <s:url> as
follows:
<s:url id="externlaURL" value="http://localhost:8080/test" encode="true">
 <s:param name="returnURL" value='%{request.getHeader("Referer")}" />
</s:url>
<s:a id="Go" href="%{externalURL}" > Go to Another Application Server page
</s:a>

Basically, I want to go to external site running on another app server and
appending returnURL parameter which will be used on the exernal site to come
back to this web application page running on different server.

e.g returnURL contains: http://localhost:7001/demo/index.action?id=123

so the expected URL generation is:
http://localhost:8080/test?returnURL=http://localhost:7001/demo/index.action?id=123

But when i am checking the page source, it shows the %20D, %20F which means
its converting the : / & character exist in returnURL parameter value. 

Please give your suggesstion to resolve this problem.

2. The situation is like same as above problem as follows:

Web App1 - Page 1 - Go Link points to Page 2 with returnURL parameter points
to "Referer" value.
Web App2 - Page 2 - Go back link points to value of return URL i.e. Page 1

Both Web App1 and 2 are running on different server.

Page 1 has the link generation code mentioned in the problem 1. When i click
on 'Go to Another Application Server page ' link, it takes me successfully
to Page 2. Now, i am clicking on Go back link which contains href property
set to returnURL parameter value to come back to Page 1.

Problem is that when i am coming back to page 1 from page 2, its errors out.
But error goes offf if i hit refresh or opens this page in a new window. So,
is it due to switching context between 2 web server in the same browser
window or what?

~Gurpreet Singh



Arup Francis 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-tp12407850p19682977.html
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


Re: How to access request & session objects in jsp using struts2 tags

Posted by afp <ar...@bankofamerica.com>.
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 <ar...@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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Alvaro Sanchez-Mariscal <al...@gmail.com>.
Use JSTL: ${requestContext.currentSection}.

The same applies for session: ${sessionContext. ...}

Alvaro.

On 8/30/07, Chris Pratt <th...@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 <ar...@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
>
>


-- 
Alvaro Sanchez-Mariscal Arnaiz
Java EE Architect & Instructor
alvaro.sanchezmariscal@gmail.com

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


Re: How to access request & session objects in jsp using struts2 tag

Posted by Chris Pratt <th...@gmail.com>.
It's JSP 2.0 EL (which isn't specific to JSTL any longer) so you
should be able to use it.  Otherwise you'll have to look up the
analogs in OGNL (I don't have my reference handy).
  (*Chris*)

On 8/30/07, afp <ar...@bankofamerica.com> wrote:
>
> np chris!
>
> Is tat using JSTL? I am not using JSTL in my app. How can I get it working
> in/using struts2 tags  <s:tags /> ??
>
> Arup
>
> Chris Pratt wrote:
> >
> > OK, sorry, I thought you were talking about the action.  If you want
> > at the attributes you can use ${requestScope.attributename} or
> > ${sessionScope.attributename} and if you need to get at the actual
> > accessors you can use ${pageContext.request.contextPath}
> >   (*Chris*)
> >
> > On 8/30/07, Dave Newton <ne...@yahoo.com> wrote:
> >> --- afp <ar...@bankofamerica.com> wrote:
> >> > [...] but really tat doesn't quite answer the
> >> > question. In general how do we access the request or
> >>
> >> > session in the jsp?
> >>
> >> http://struts.apache.org/2.x/docs/ognl.html
> >>
> >> > Will what I have given below work
> >>
> >> Does it work?
> >>
> >> > or what shud I be doing to make it work!
> >>
> >> I think the dot-notation will cause you problems, but
> >> I could be wrong about that--you might be able to
> >> coerce it somehow.
> >>
> >> Or you could set a flag in the action or expose an
> >> object that holds the request value.
> >>
> >> > The requirement is tat I need to access it in the
> >> jsp
> >> > and not in the action class method.
> >>
> >> Really? Or is the requirement that you be able to make
> >> decisions in the JSP based on which submit button was
> >> used?
> >>
> >> d.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> 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#a12412606
> 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


Re: How to access request & session objects in jsp using struts2 tag

Posted by afp <ar...@bankofamerica.com>.
np chris!

Is tat using JSTL? I am not using JSTL in my app. How can I get it working
in/using struts2 tags  <s:tags /> ??

Arup

Chris Pratt wrote:
> 
> OK, sorry, I thought you were talking about the action.  If you want
> at the attributes you can use ${requestScope.attributename} or
> ${sessionScope.attributename} and if you need to get at the actual
> accessors you can use ${pageContext.request.contextPath}
>   (*Chris*)
> 
> On 8/30/07, Dave Newton <ne...@yahoo.com> wrote:
>> --- afp <ar...@bankofamerica.com> wrote:
>> > [...] but really tat doesn't quite answer the
>> > question. In general how do we access the request or
>>
>> > session in the jsp?
>>
>> http://struts.apache.org/2.x/docs/ognl.html
>>
>> > Will what I have given below work
>>
>> Does it work?
>>
>> > or what shud I be doing to make it work!
>>
>> I think the dot-notation will cause you problems, but
>> I could be wrong about that--you might be able to
>> coerce it somehow.
>>
>> Or you could set a flag in the action or expose an
>> object that holds the request value.
>>
>> > The requirement is tat I need to access it in the
>> jsp
>> > and not in the action class method.
>>
>> Really? Or is the requirement that you be able to make
>> decisions in the JSP based on which submit button was
>> used?
>>
>> d.
>>
>>
>> ---------------------------------------------------------------------
>> 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#a12412606
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


Re: How to access request & session objects in jsp using struts2 tag

Posted by Chris Pratt <th...@gmail.com>.
OK, sorry, I thought you were talking about the action.  If you want
at the attributes you can use ${requestScope.attributename} or
${sessionScope.attributename} and if you need to get at the actual
accessors you can use ${pageContext.request.contextPath}
  (*Chris*)

On 8/30/07, Dave Newton <ne...@yahoo.com> wrote:
> --- afp <ar...@bankofamerica.com> wrote:
> > [...] but really tat doesn't quite answer the
> > question. In general how do we access the request or
>
> > session in the jsp?
>
> http://struts.apache.org/2.x/docs/ognl.html
>
> > Will what I have given below work
>
> Does it work?
>
> > or what shud I be doing to make it work!
>
> I think the dot-notation will cause you problems, but
> I could be wrong about that--you might be able to
> coerce it somehow.
>
> Or you could set a flag in the action or expose an
> object that holds the request value.
>
> > The requirement is tat I need to access it in the
> jsp
> > and not in the action class method.
>
> Really? Or is the requirement that you be able to make
> decisions in the JSP based on which submit button was
> used?
>
> d.
>
>
> ---------------------------------------------------------------------
> 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: How to access request & session objects in jsp using struts2 tags

Posted by afp <ar...@bankofamerica.com>.
> [...] but really tat doesn't quite answer the 
> question. In general how do we access the request or

> session in the jsp?

http://struts.apache.org/2.x/docs/ognl.html

>> Tried what is given there and it was not working which was why I put in
>> the post :(

> Will what I have given below work 

Does it work?

>> Nope :(
> or what shud I be doing to make it work!

I think the dot-notation will cause you problems, but
I could be wrong about that--you might be able to
coerce it somehow.

Or you could set a flag in the action or expose an
object that holds the request value.

>> Could do this but really I think having a parameter for the purpose
>> (explained below) is overkill!
> The requirement is tat I need to access it in the
jsp
> and not in the action class method. 

Really? Or is the requirement that you be able to make
decisions in the JSP based on which submit button was
used?

>> My page has few sections which will be either all shown or only one shown
>> (hiding using css). Now to make all of them shown I have a "Display All
>> Sections" link at the top clicking on which I show all the sections
>> expanded. Now this is done using javascript. Now these sections contain
>> lots of form data which needs to be filled in by the user. If user does
>> not fill in all details and then submits the form by clicking the button
>> at te bottom of the page then validator will throw errors which will be
>> shown to the user, now if there are errors then the same page will be
>> shown and all the sections need to be shown expanded on reload. If
>> validation errors are present then we will not enter the action class
>> method and so the question of setting a flag based on whether or not the
>> buton was clicked does not arise as we won't anyway enter the action
>> class method. (This can maybe be overriden by modifying the interceptor
>> related to validation but really its an overkill for this!) Now te way I
>> was thinking was to determine whether the button was clicked in the jsp
>> and based on tat call a javascript function which wud set all sections to
>> expanded mode. This was why I am trying to access the request in the jsp.
>> Hope this made sense!
 
Arup

newton.dave wrote:
> 
> --- afp <ar...@bankofamerica.com> wrote:
>> [...] but really tat doesn't quite answer the 
>> question. In general how do we access the request or
> 
>> session in the jsp?
> 
> http://struts.apache.org/2.x/docs/ognl.html
> 
>> Will what I have given below work 
> 
> Does it work?
> 
>> or what shud I be doing to make it work!
> 
> I think the dot-notation will cause you problems, but
> I could be wrong about that--you might be able to
> coerce it somehow.
> 
> Or you could set a flag in the action or expose an
> object that holds the request value.
> 
>> The requirement is tat I need to access it in the
> jsp
>> and not in the action class method. 
> 
> Really? Or is the requirement that you be able to make
> decisions in the JSP based on which submit button was
> used?
> 
> d.
> 
> 
> ---------------------------------------------------------------------
> 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#a12412462
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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Dave Newton <ne...@yahoo.com>.
--- afp <ar...@bankofamerica.com> wrote:
> [...] but really tat doesn't quite answer the 
> question. In general how do we access the request or

> session in the jsp?

http://struts.apache.org/2.x/docs/ognl.html

> Will what I have given below work 

Does it work?

> or what shud I be doing to make it work!

I think the dot-notation will cause you problems, but
I could be wrong about that--you might be able to
coerce it somehow.

Or you could set a flag in the action or expose an
object that holds the request value.

> The requirement is tat I need to access it in the
jsp
> and not in the action class method. 

Really? Or is the requirement that you be able to make
decisions in the JSP based on which submit button was
used?

d.


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


Re: How to access request & session objects in jsp using struts2 tags

Posted by afp <ar...@bankofamerica.com>.
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 <th...@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 <ar...@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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Dave Newton <ne...@yahoo.com>.
> 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 <th...@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 <ar...@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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Chris Pratt <th...@gmail.com>.
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 <ar...@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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Arup Francis <ar...@bankofamerica.com>.
Oops sorry! yes thats rite...
well my requirement was getting the equivalent of <%=
request.getParameter("paramname") %> in 
struts2 using s2 tags alone and for that we have to look into parameters
object and not the request object. My understanding was tat since request
parameters wud be coming under the request object I have to get it from
there and so I was trying this in vain <s:property
value="#request['paramName']" />

Arup  

newton.dave wrote:
> 
> --- afp <ar...@bankofamerica.com> wrote:
>> To access the request object in the jsp using
>> struts2 tags this is what we have to do
> 
> <s:property value="#parameters['paramName']" />
> 
> For the sake of completeness this accesses request
> parameters, not the request object.
> 
> d.
> 
> 
> ---------------------------------------------------------------------
> 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#a12437397
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


Re: How to access request & session objects in jsp using struts2 tags

Posted by Dave Newton <ne...@yahoo.com>.
--- afp <ar...@bankofamerica.com> wrote:
> To access the request object in the jsp using
> struts2 tags this is what we have to do

<s:property value="#parameters['paramName']" />

For the sake of completeness this accesses request
parameters, not the request object.

d.


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


Re: How to access request & session objects in jsp using struts2 tags

Posted by afp <ar...@bankofamerica.com>.
First issue solved!!
To access the request object in the jsp using struts2 tags this is what we
have to do

<s:property value="#parameters['requestattributename']" />

if ur url was *.action?abc=xyz then 
<s:property value="#parameters['abc']" /> would give the value of the
request parameter called abc and print xyz in this case. So learning is tat
we have to use #parameters[''] instead of #request[''] which was what I was
trying to do earlier!

Arup

afp 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#a12424366
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