1
votes

Hey i am new to struts2 or even to Struts so, i was looking the ways by which we can pass messages from action class to jsp page

  • i.e I have a login page and if login fails then i want to send error message to jsp page for what reasons the login was failed or even if login was successful then i want to show a login successful popup to the user

Thanks

3
You will have to use ajax for this.Buhake Sindi
depends on how the login form is submitted. It is normal form submission or an ajax submission ?coding_idiot
@BuhakeSindi Ajax login is slightly different then normal form login.Roman C

3 Answers

1
votes

Yes, you can pass messages to jsp in struts2.You can use a code like this addActionMessage("You are valid user!"); in the action class. I think you need to extend ActionSupport for this. http://www.mkyong.com/struts2/struts-2-actionerror-actionmessage-example/

1
votes

In your action

addActionMessage("Welcome")
addErrorMessage("Not Logged in")

in your jsp:

 <s:actionmessage/>
 <s:actionerror/>
1
votes

In your action class, you will be calling addActionMessage() for success message and addActionError() for the failure message.

To display the error on the JSPs you will use <s:actionmessage /> and <s:actionerror />.