In this tutorial, you will see the use of action tag of struts2.2.1. It is a non-form UI tag in struts framework. It display a error of action error exists.
Directory structure of actionerror and actionmessage tag example.![]() |
1- index.jsp
|
<html> <head><title>Actionerror_Tag_Example</title> </head> <body><h1>Actionerror_Tag_Example</h1><hr> <a href="ActionError.action">Actionerror_Tag_Example</a> </body> </html> |
2-LoginPage.jsp
|
<%@taglib uri="/struts-tags" prefix="s" %> <html> <head><title>Actionerror_Tag_Example</title></head> <body><h1>Actionerror_Tag_Example</h1><hr> <font color="Red" ><s:actionerror/></font> <s:form action="LoginValidation"> <s:textfield name="loginID" label="LoginID"></s:textfield> <s:submit label="Login"></s:submit> </s:form></body> </html> |
3-ActionErrorAction.java
|
package roseindia.action; import org.apache.struts2.components.ActionMessage; import com.opensymphony.xwork2.ActionSupport; public class ActionErrorAction extends ActionSupport { private String loginID; public String getLoginID() { return loginID; } public void setLoginID(String loginID) { this.loginID = loginID; } public String execute(){ if (getLoginID().equals("gangwar.bharat25")) { addActionMessage("You are a valid user."); return SUCCESS; } else { addActionError("Please enter valid login id"); return ERROR; } } public String display() { return NONE; } } |
4_struts.xml
|
<struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <package name="bharat" extends="struts-default" namespace="/"> <action name="ActionError" class="roseindia.action.ActionErrorAction" method="display"> <result name="none">JSPpages/LoginPage.jsp</result></action><action name="LoginValidation" class="roseindia.action.ActionErrorAction"> <result name="success" >JSPpages/WelcomePage.jsp</result> <result name="error" >JSPpages/LoginPage.jsp</result></action> </package> </struts> |
5_WelcomePage.jsp
|
<%@taglib uri="/struts-tags" prefix="s" %> <html> <head><title>Actionerror_Tag_Example</title> <style type="text/css"> table {background: yellow;} td {text-align: center;} </style> </head> <body><h1>Actionerror_Tag_Example</h1><hr> <table><tr><td ><font color="green"><s:actionmessage/></font></td></tr></table> Name : <s:property value="loginID"/> </body> </html> |
indexJsp.gif

LoginPage.gif

LoginIdError.gif
WelComePage.gif

ValidIdPage.gif
