aspose file tools*
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
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!
 
Consider Paul's rocket mass heater.
 
subject: How to compare request attribute in Jsp in struts2