|
Struts 2 Non-form Tags (UItags) |
|
Apache Struts is an open-source framework
used to develop Java web applications. In this
section, struts 2 non-form tags (UItags) will
be discussed. Just download the zip file “struts2nonformuitags.zip” from any link given
below of each page of this article, unzip it and
copy this application to the webapps directory
of Tomcat. Start tomcat and write http:// localhost:8080/struts2nonformuitags to the
address bar. You can examine the result of each
tag from the index page.
1. Action Error and Action Message Tags
Example
The actionerror tag is a UI tag that renders
action errors (in the jsp pages.) if they exist
while the actionmessage tag renders action
messages if they exist.
|
|
Add the following code snippet into the
struts.xml file.
struts.xml
<action name=”actionerrorTag”>
<result>/pages/nonformTags/login.jsp</
result>
</action>
<action name=”login”
class=”net.javajazzup.CheckValidUser”>
<result name=”input”>/pages/
nonformTags/login.jsp</result>
<result name=”error”>/pages/
nonformTags/error.jsp</result>
<result>/pages/nonformTags/
validuser.jsp</result>
</action>
Create an action class that uses methods
addActionMessage(String) and
addActionError(String) within the execute()
method. The addActionMessage(String) will
print the passed string on the success jsp page
while the addActionError(String) will print the
passed string on the error jsp page.
CheckValidUser.java
package net.javajazzup;
import
com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class CheckValidUser extends
ActionSupport {
private String username = null;
private String password = null;
public String execute() throws Exception{
if ((getUsername().equals(“javajazzup”))
&&
(getPassword().equals(“javajazzup”))){
addActionMessage(“Valid User”);
return SUCCESS;
}
else{
addActionError(“Invalid User”);
return ERROR;
}
} |
|
March 2008 | Java Jazz Up | 29 |
|
|
|
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 |
|
|
|
|
|
|
|
|
|