Struts2.2.1 password tag example.
Posted on: January 15, 2011 at 12:00 AM
In this tutorial, you will see the use of password tag of struts2.2.1.

Struts2.2.1 password tag example.

In this tutorial, you will see the use of password tag of struts2.2.1. It is a  UI tag in struts framework. It display a input tag of type password.

Directory structure of password  tag example.

 1- index.jsp

<html>ADS_TO_REPLACE_1

<head>

<title>Password Tag Example</title>

</head>ADS_TO_REPLACE_2

<body>

<h1>Password Tag Example</h1>

<hr>ADS_TO_REPLACE_3

<a href="PasswordTag.action">Password Tag Example</a>

</body>

</html>

2-PasswordTag.jspADS_TO_REPLACE_4

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

<html>

<head>ADS_TO_REPLACE_5

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Password Tag Example</title>

</head>ADS_TO_REPLACE_6

<body>

<s:actionerror/>

<s:form action="ResultPasswordTag.action">ADS_TO_REPLACE_7

<s:textfield name="userName" key="Username"></s:textfield>

<s:password name="password" key="Password:"></s:password>

<s:submit></s:submit>ADS_TO_REPLACE_8

</s:form>

</body>

</html>

 3-PasswordTag.javaADS_TO_REPLACE_9

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class PasswordTag extends ActionSupport {ADS_TO_REPLACE_10

private String userName;

private String password;

public String execute() {ADS_TO_REPLACE_11

if (getUserName().equals("Gyan") && getPassword().equals("Singh")) {

addActionMessage("You are a valid user.");

return SUCCESS;ADS_TO_REPLACE_12

} else {

addActionError("Please enter valid Username and Password ");

return ERROR;ADS_TO_REPLACE_13

}

}

public String getUserName() {ADS_TO_REPLACE_14

return userName;

}

public void setUserName(String userName) {ADS_TO_REPLACE_15

this.userName = userName;

}

public String getPassword() {ADS_TO_REPLACE_16

return password;

}

public void setPassword(String password) {ADS_TO_REPLACE_17

this.password = password;

}

public String display() {ADS_TO_REPLACE_18

return NONE;

}

}

4_struts.xmlADS_TO_REPLACE_19

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />

<constant name="struts.devMode" value="false" />ADS_TO_REPLACE_20

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

<action name="PasswordTag" class="roseindia.PasswordTag" method="display">

<result name="none">/PasswordTag.jsp</result>ADS_TO_REPLACE_21

</action>

<action name="ResultPasswordTag" class="roseindia.PasswordTag">

<result name="error">/PasswordTag.jsp</result>ADS_TO_REPLACE_22

<result name="success">/Welcome.jsp</result>

</action>

</package>ADS_TO_REPLACE_23

</struts>

5_Welcome.jsp

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

<html>ADS_TO_REPLACE_24

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Password Tag Example</title>ADS_TO_REPLACE_25

</head>

<body>

<s:form name="PasswordTagAction"><s:actionmessage/>ADS_TO_REPLACE_26

Welcome : <s:property value="userName"/><br>

Your Password is : <s:property value="password"/></s:form>

</body>ADS_TO_REPLACE_27

</html>

ADS_TO_REPLACE_28

Download Select Source CodeADS_TO_REPLACE_29

Related Tags for Struts2.2.1 password tag example.:

Advertisements

Ads

 
Advertisement null

Ads