<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Employee Form</title> </head> <body> <s:form action="empinfo" method="post"> <s:textfield name="name" label="Name" size="20" /> <s:textfield name="age" label="Age" size="20" /> <s:submit name="submit" label="Submit" align="center" /> </s:form> </body> </html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Success</title> </head> <body> Employee Information is captured successfully. </body> </html>
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.opensymphony.xwork2.validator.annotations.*;
@Results({
@Result(name="success", location="/success.jsp"),
@Result(name="input", location="/index.jsp")
})
public class Employee extends ActionSupport{
private String name;
private int age;
@Action(value="/empinfo")
public String execute()
{
return SUCCESS;
}
@RequiredFieldValidator( message = "The name is required" )
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@IntRangeFieldValidator(message = "Age must be in between 28 and 65",
min = "29", max = "65")
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
<init-param>
<param-name>struts.devMode</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
@Namespace("/content")
public class Employee extends ActionSupport{
...
}
@Result(name="success", value="/success.jsp")
public class Employee extends ActionSupport{
...
}
@Results({
@Result(name="success", value="/success.jsp"),
@Result(name="error", value="/error.jsp")
})
public class Employee extends ActionSupport{
...
}
public class Employee extends ActionSupport{
@After
public void isValid() throws ValidationException {
// validate model object, throw exception if failed
}
public String execute() {
// perform secure action
return SUCCESS;
}
}
public class Employee extends ActionSupport{
@Before
public void isAuthorized() throws AuthenticationException {
// authorize request, throw exception if failed
}
public String execute() {
// perform secure action
return SUCCESS;
}
}
public class Employee extends ActionSupport{
@BeforeResult
public void isValid() throws ValidationException {
// validate model object, throw exception if failed
}
public String execute() {
// perform action
return SUCCESS;
}
}
public class Employee extends ActionSupport{
@ConversionErrorFieldValidator(message = "Default message",
key = "i18n.key", shortCircuit = true)
public String getName() {
return name;
}
}
public class Employee extends ActionSupport{
@DateRangeFieldValidator(message = "Default message",
key = "i18n.key", shortCircuit = true,
min = "2005/01/01", max = "2005/12/31")
public String getDOB() {
return dob;
}
}
public class Employee extends ActionSupport{
@DoubleRangeFieldValidator(message = "Default message",
key = "i18n.key", shortCircuit = true,
minInclusive = "0.123", maxInclusive = "99.987")
public String getIncome() {
return income;
}
}
public class Employee extends ActionSupport{
@EmailValidator(message = "Default message",
key = "i18n.key", shortCircuit = true)
public String getEmail() {
return email;
}
}
public class Employee extends ActionSupport{
@IntRangeFieldValidator(message = "Default message",
key = "i18n.key", shortCircuit = true,
min = "0", max = "42")
public String getAge() {
return age;
}
}
public class Employee extends ActionSupport{
@RequiredFieldValidator(message = "Default message",
key = "i18n.key", shortCircuit = true)
public String getAge() {
return age;
}
}
public class Employee extends ActionSupport{
@RequiredStringValidator(message = "Default message",
key = "i18n.key", shortCircuit = true, trim = true)
public String getName() {
return name;
}
}
public class Employee extends ActionSupport{
@StringLengthFieldValidator(message = "Default message",
key = "i18n.key", shortCircuit = true,
trim = true, minLength = "5", maxLength = "12")
public String getName() {
return name;
}
}
public class Employee extends ActionSupport{
@UrlValidator(message = "Default message",
key = "i18n.key", shortCircuit = true)
public String getURL() {
return url;
}
}
public class Employee extends ActionSupport{
@Validations(
requiredFields =
{@RequiredFieldValidator(type = ValidatorType.SIMPLE,
fieldName = "customfield",
message = "You must enter a value for field.")},
requiredStrings =
{@RequiredStringValidator(type = ValidatorType.SIMPLE,
fieldName = "stringisrequired",
message = "You must enter a value for string.")}
)
public String getName() {
return name;
}
}
@CustomValidator(type ="customValidatorName", fieldName = "myField")
@Conversion()
public class ConversionAction implements Action {
}
@CreateIfNull( value = true ) private List<User> users;
@Element( value = com.acme.User ) private List<User> userList;
@Key( value = java.lang.Long.class ) private Map<Long, User> userMap;
@KeyProperty( value = "userName" ) protected List<User> users = null;
@TypeConversion(rule = ConversionRule.COLLECTION,
converter = "java.util.String")
public void setUsers( List users ) {
this.users = users;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有