简体   繁体   中英

How to send Messages From Struts Action class to jsp page

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

  • ie 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

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/

In your action

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

in your jsp:

 <s:actionmessage/>
 <s:actionerror/>

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 /> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM