wood burning stoves 2.0*
The moose likes Struts and the fly likes variable value not being passed to jsp from Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "variable value not being passed to jsp from Action" Watch "variable value not being passed to jsp from Action" New topic
Author

variable value not being passed to jsp from Action

sankey jain
Ranch Hand

Joined: Apr 29, 2010
Posts: 58
Hi all,

This is what i am doing

declared a variable called ack in the action class, created the getter setters for the same.
variable is getting it s value from a function

I am trying to access this variable in a jsp called menubar.jsp.
it is a generic jsp, a jsp which is used everywhere

i have a If loop in the jsp, to check for a particular value in the variable, not able to do so, as the value is not being passed

help please

jsp code



>








suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 60
hi,
you must put the values into request or seeeion and this 'request or seeeion' iterate over the '.jsp'and you able to
get the values into the '.jsp'
sankey jain
Ranch Hand

Joined: Apr 29, 2010
Posts: 58
okay, how do i do that ?
not very sure on this.

Actually, i have done a similar implementation where i check for count, and i was able to do it.

i also understand that struts 2 has the capability where you can access the values in the jsp, as it is automatically placed in the session.

not sure how right i am
suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 60
if you want to store in request then you have to be getter and setter method of that object.
and getin '.jsp' using <s:property values="#request.objectname"> then you get the values of that object.
sankey jain
Ranch Hand

Joined: Apr 29, 2010
Posts: 58
So my code should look like this after your suggestion

<s:if test="%{ackvalue == 'WES'}">
<s:property value="request.ackValue"/>
<li id="logoutMenu" ><a id="logout"

correct ?

Session Put Statement in Action class

session.put(ackValue,ConflictConstants.SESSION_ATTRIBURE_ACK_VALUE);
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

sankey jain wrote:i also understand that struts 2 has the capability where you can access the values in the jsp, as it is automatically placed in the session.

Nothing is automatically placed in the session.
sankey jain wrote:

That's almost certainly not what you meant, although it would work. The key value is first--it's just a map.
sankey jain
Ranch Hand

Joined: Apr 29, 2010
Posts: 58
David Newton wrote:
sankey jain wrote:i also understand that struts 2 has the capability where you can access the values in the jsp, as it is automatically placed in the session.

Nothing is automatically placed in the session.
sankey jain wrote:

That's almost certainly not what you meant, although it would work. The key value is first--it's just a map.


okay, understood.
i guess the jsp, action class are tagged together by a particular action in the struts.xml
that is how i was able to do the above in one instance.

So using the session statement and session.request in the jsp, i can retrieve the value.
right ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

sankey jain wrote:[...] and session.request in the jsp, i can retrieve the value.

I don't know what you mean by "session.request".

Wouldn't it just be easier to try something, and if it doesn't work, PostRealCode and ask a question?
sankey jain
Ranch Hand

Joined: Apr 29, 2010
Posts: 58
This is what i have done now



ConflictConstants.SESSION_ATTRIBURE_ACK_VALUE constant's value is ackval

Now, when i switch to debug, the value for ackValue is populated
How do i access the variable in the Jsp ?

Below is the code where i want to access it, have placed my comments accordingly



sankey jain
Ranch Hand

Joined: Apr 29, 2010
Posts: 58
David Newton wrote:
sankey jain wrote:[...] and session.request in the jsp, i can retrieve the value.

I don't know what you mean by "session.request".

Wouldn't it just be easier to try something, and if it doesn't work, PostRealCode and ask a question?


This is what i have done now



ConflictConstants.SESSION_ATTRIBURE_ACK_VALUE constant's value is ackval

Now, when i switch to debug, the value for ackValue is populated
How do i access the variable in the Jsp ?

Below is the code where i want to access it, have placed my comments accordingly



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

#session.whateverATTRIBUREis

Fix the typo.

You can also probably do something like #session[@full.constants.package@ATTRIBURE]
sankey jain
Ranch Hand

Joined: Apr 29, 2010
Posts: 58
David Newton wrote:#session.whateverATTRIBUREis

Fix the typo.

You can also probably do something like #session[@full.constants.package@ATTRIBURE]


Hi David,

Thanks a lot for the support :).. Appreciate it
have done the below

hope it works

sankey jain
Ranch Hand

Joined: Apr 29, 2010
Posts: 58
sankey jain wrote:
David Newton wrote:#session.whateverATTRIBUREis

Fix the typo.

You can also probably do something like #session[@full.constants.package@ATTRIBURE]


Hi David,

Thanks a lot for the support :).. Appreciate it
have done the below

hope it works




The Above worked.. Thanks a lot for the help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variable value not being passed to jsp from Action
 
Similar Threads
IE 7 Error on Page
Struts Jsp Restrictions
Add Effect to Link
s:url
passing values from struts2 form to javascript