Struts2.2.1 actionerror  and actionmessage tag example.
Posted on: January 13, 2011 at 12:00 AM
in this example, you will see the implementation Struts2.2.1 actionerror  and actionmessage tag .

Struts2.2.1 actionerror  and actionmessage tag example.

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>ADS_TO_REPLACE_1

<head><title>Actionerror_Tag_Example</title>

</head>

<body><h1>Actionerror_Tag_Example</h1><hr>ADS_TO_REPLACE_2

<a href="ActionError.action">Actionerror_Tag_Example</a>

</body>

</html>

2-LoginPage.jsp ADS_TO_REPLACE_3

<%@taglib uri="/struts-tags" prefix="s" %>

<html>

<head><title>Actionerror_Tag_Example</title></head>ADS_TO_REPLACE_4

<body><h1>Actionerror_Tag_Example</h1><hr>

<font color="Red" ><s:actionerror/></font>

<s:form action="LoginValidation">ADS_TO_REPLACE_5

<s:textfield name="loginID" label="LoginID"></s:textfield>

<s:submit label="Login"></s:submit>

</s:form></body>ADS_TO_REPLACE_6

</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" />ADS_TO_REPLACE_7

<package name="bharat" extends="struts-default" namespace="/">

<action name="ActionError" class="roseindia.action.ActionErrorAction" method="display">

<result name="none">JSPpages/LoginPage.jsp</result></action>ADS_TO_REPLACE_8

<action name="LoginValidation" class="roseindia.action.ActionErrorAction">

<result name="success" >JSPpages/WelcomePage.jsp</result>

<result name="error" >JSPpages/LoginPage.jsp</result></action>ADS_TO_REPLACE_9

</package>

</struts>

5_WelcomePage.jsp

<%@taglib uri="/struts-tags" prefix="s" %>

<html>ADS_TO_REPLACE_10

<head><title>Actionerror_Tag_Example</title>

<style type="text/css">

table {background: yellow;}ADS_TO_REPLACE_11

td {text-align: center;} </style>

</head>

<body><h1>Actionerror_Tag_Example</h1><hr>ADS_TO_REPLACE_12

<table><tr><td ><font color="green"><s:actionmessage/></font></td></tr></table>

Name : <s:property value="loginID"/>

</body>ADS_TO_REPLACE_13

</html>

indexJsp.gif

LoginPage.gifADS_TO_REPLACE_14

LoginIdError.gif

ADS_TO_REPLACE_15

WelComePage.gif

ValidIdPage.gifADS_TO_REPLACE_16

Download Select Source Code


Related Tags for Struts2.2.1 actionerror  and actionmessage tag example. :

Advertisements

Ads

Ads

 
Advertisement null

Ads