Prem
Prem

Reputation: 101

Pass parameter value from struts2.xml result to jsp

I have a program in which business logic return some data. that data needs to show on the jsp. i am able to forward to the jsp based on the result but how can i send the return value. e.g.

public String createuser(String strUser,String strPassword)
{
     String strReturnValue="S0000";
     try
     {
       // My code;
     }
     catch(Exception ex)
     {

     }
     return strReturnValue+"Token";
}

Struts.xml

<action name="RegUser" class="....">
   <result name="success">/UIShow.jsp</result>
   <result name="error>/UIError.jsp</result>
</action>

in jsp i want to show this token value on success; How can I do this?

Upvotes: 0

Views: 1384

Answers (1)

Roy Six
Roy Six

Reputation: 298

You may want to check out the Hello World Struts 2 application because it provides a good example of how to do this.

  1. In your Action class, you can create a String field and appropriate getter method for the token value so that your JSP can retrieve it. In your RegUser action method you will want to assign the field to the result from the business logic, like tokenValue = createUser(user, password);

  2. In your UIShow.jsp you can use a struts 2 tag s:property to display the token value, like <s:property value="tokenValue"/>

Or, since this is just a String, it may be simpler for you to use the addActionMessage method from ActionSupport in your Action class (pass in the String result of the business logic into addActionMessage) and then use the s:actionmessage tag in your JSP to display the token value.

Upvotes: 1

Related Questions