Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to compare request attribute in Jsp in struts2

 
gyanendra ojha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic