Magazine
 
Struts 2 Non-form Tags (UItags)

//Set and get the user name
public void setUsername(String name){
username = name;
}
public String getUsername(){
return username;
}
//set and get the password
public void setPassword(String pass){
password = pass;
}
public String getPassword(){
return password;
}
}

Create a login jsp page as shown:

login.jsp

<%@ taglib prefix=”s” uri=”/struts-tags” %>
<html>
<head>
<title>Actionerror Tag Example</title>
<body>
<s:form action=”login” method=”POST”>
<s:textfield label=”User Name”
name=”username” size=”20" maxlength=”10"
/>
<s:password label=”Password”
name=”password” size=”20" maxlength=”10"
/>
<s:submit value=”Submit” />
</s:form>
</body>
</html>

Create a jsp page that will display your error message (when fails to logged-in) using the empty <s:actionerror /> tag as shown:

error.jsp

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

 

<head>
<title></title>
<body>
<h1>
<s:actionerror />
</h1>
<a href=”/struts2nonformuitags/
javajazzup/actionerrorTag.action”>Go Back</
a>
</body>
</html>

Create a jsp page that will display a message (when successfully logged-in) using the empty <s:actionmessage /> tag as shown:

validuser.jsp

<%@ taglib prefix=”s” uri=”/struts-tags” %>
<html>
<head>
<title>Actionerror Tag Example</title>
<body>
<h1>
<s:actionmessage />
</h1>
</body>
</html>

You will see the output of the login.jsp as shown below. Put correct user name and password.

You will get output:

Enter the wrong user name or password in the
login page.

Mar  2008 | Java Jazz Up |30
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59,

Download PDF