EmailValidationAction.java
-------------------------------------------
package kites;
import com.opensymphony.xwork2.ActionSupport;
public class EmailValidationAction extends ActionSupport {
private String email;
public String getEmail() {
return email; }
public void setEmail(String email) {
this.email = email; }
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS; }
}
------------------------------------------------------------------------------------------------------------------------------
EmailValidationAction-validation.xml
------------------------------------------------------------
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="email">
<field-validator type="requiredstring">
<message>Email id is required</message>
</field-validator>
<field-validator type="email">
<message>Please enter valid email id.</message>
</field-validator>
</field>
</validators>
---------------------------------------------------------------------------------------------------------------------------------
index.jsp
--------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head><title>Email_Validator_Example</title><s:head/></head>
<body>Email_Validator_Example.....
<s:form action="emailvalidation.action">
<s:textfield name="email" label="Email-Id :"></s:textfield>
<s:submit></s:submit></s:form>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------------
struts.xml
----------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<package name="kites" namespace="/" extends="struts-default">
<action name="emailvalidation" class="kites.EmailValidationAction">
<result name="input">index.jsp</result>
<result name="error">index.jsp</result>
<result>successJsp.jsp</result>
</action></package>
</struts>
-------------------------------------------------------------------------------------------------------------------------------
success.jsp
-------------------
<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head><title>Insert title here</title></head>
<body>Email-Id....
<s:property value="email"/></body>
</html>
-------------------------------------------------------------------------------------------------------------------------------
web.xml
-----------------
<?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>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------
package kites;
import com.opensymphony.xwork2.ActionSupport;
public class EmailValidationAction extends ActionSupport {
private String email;
public String getEmail() {
return email; }
public void setEmail(String email) {
this.email = email; }
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return SUCCESS; }
}
------------------------------------------------------------------------------------------------------------------------------
EmailValidationAction-validation.xml
------------------------------------------------------------
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="email">
<field-validator type="requiredstring">
<message>Email id is required</message>
</field-validator>
<field-validator type="email">
<message>Please enter valid email id.</message>
</field-validator>
</field>
</validators>
---------------------------------------------------------------------------------------------------------------------------------
index.jsp
--------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head><title>Email_Validator_Example</title><s:head/></head>
<body>Email_Validator_Example.....
<s:form action="emailvalidation.action">
<s:textfield name="email" label="Email-Id :"></s:textfield>
<s:submit></s:submit></s:form>
</body>
</html>
--------------------------------------------------------------------------------------------------------------------------------
struts.xml
----------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<package name="kites" namespace="/" extends="struts-default">
<action name="emailvalidation" class="kites.EmailValidationAction">
<result name="input">index.jsp</result>
<result name="error">index.jsp</result>
<result>successJsp.jsp</result>
</action></package>
</struts>
-------------------------------------------------------------------------------------------------------------------------------
success.jsp
-------------------
<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head><title>Insert title here</title></head>
<body>Email-Id....
<s:property value="email"/></body>
</html>
-------------------------------------------------------------------------------------------------------------------------------
web.xml
-----------------
<?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>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
------------------------------------------------------------------------------------------------------------------------------