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>< head>< title>Password Tag Example</title></ head>< body>< h1>Password Tag Example</h1>< hr>< a href="PasswordTag.action">Password Tag Example</a></ body></ html> |
2-PasswordTag.jsp
|
<%@ taglib prefix="s" uri="/struts-tags"%>< html>< head>< meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">< title>Password Tag Example</title></ head>< body>< s:actionerror/>< s:form action="ResultPasswordTag.action"> <s:textfield name="userName" key="Username"></s:textfield> <s:password name="password" key="Password:"></s:password> <s:submit></s:submit></s:form> </body> </html> |
3-PasswordTag.java
|
package roseindia;import com.opensymphony.xwork2.ActionSupport;public class PasswordTag extends ActionSupport { private String userName; private String password; public String execute() { if (getUserName().equals("Gyan") && getPassword().equals("Singh")) {addActionMessage( "You are a valid user."); return SUCCESS;} else {addActionError( "Please enter valid Username and Password "); return ERROR;} } public String getUserName() { return userName;} public void setUserName(String userName) { this.userName = userName;} public String getPassword() { return password;} public void setPassword(String password) { this.password = password;} public String display() { return NONE;} } |
4_struts.xml
|
<struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <package name="roseindia" extends="struts-default" namespace="/"> <action name="PasswordTag" class="roseindia.PasswordTag" method="display"> <result name="none">/PasswordTag.jsp</result> </action> <action name="ResultPasswordTag" class="roseindia.PasswordTag"> <result name="error">/PasswordTag.jsp</result> <result name="success">/Welcome.jsp</result> </action> </package> </struts> |
5_Welcome.jsp
|
<%@ taglib prefix="s" uri="/struts-tags" %>< html>< head>< meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">< title>Password Tag Example</title></ head>< body>< s:form name="PasswordTagAction"><s:actionmessage/>Welcome : <s:property value="userName"/><br>Your Password is : <s:property value="password"/></s:form></ body></ html> |



