wood burning stoves 2.0*
The moose likes Struts and the fly likes How to compare request attribute in Jsp in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to compare request attribute in Jsp in struts2" Watch "How to compare request attribute in Jsp in struts2" New topic
Author

How to compare request attribute in Jsp in struts2

gyanendra ojha
Greenhorn

Joined: May 16, 2007
Posts: 11
hi All,
i want a compare a request attribute (say "actionName") that has been set in a Action class in a jsp with struts2 tag ( i.e </s:if> ) in a Struts2 application.
but, my code is not working . please, check where i am wrong and suggest me right way to do it.

i have also visited Struts2 documentation but was in vain.

My Action :---->

public class AboutProject extends ActionSupport {

public String execute() throws Exception {

String actionName=getActionName();
HttpServletRequest request =
ServletActionContext.getRequest();
request.setAttribute("actionName", "edit");
return "SUCCESS";
}
}



My JSP :--->

<s:if test="%{actionName}=='edit'">
<tr> <td> action is Edit </td></tr>
</s:if>
<s:else>
<tr> <td> action is Not Edit </td></tr>
</s:else>
Ian Robinson
Greenhorn

Joined: Jul 16, 2008
Posts: 1
<s:if test="%{actionName}=='edit'">

will look in the root of the value stack - basically, you action.
To reference the request you will need something like

<s:if test="%{#request.actionName}=='edit'">

If memory serves me right!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to compare request attribute in Jsp in struts2
 
Similar Threads
Problem of resubmisson in struts2
Struts2 variable inside javascript
Struts2 test condition in s:if not working
Struts2: Compare request parameter not working
[Struts2] losing display only(prepopulated) values of the form if the validaiton fails