ActionSupport Class Example in Struts 2.0
Previous | Home | Next |
ActionSupport Class Example using Struts 2.0 the following tool are required for run this example
- JDK 1.5
- MyEclipse IDE
- Server Tomcat 6.0
- Struts 2.0 jar file
Directory Structure of ActionSupport Example in Struts 2.0 Using MyEclipse IDE
index.jsp<%@taglib uri="/struts-tags" prefix="s"%> <s:form action="register"> <s:textfield name="name" label="Name"/> <s:password name="password" label="Password"/> <s:textfield name="mailId" label="MailId"/> <s:submit value="Register"/> </s:form>web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>f1</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>f1</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>struts.xml<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="demo" extends="struts-default"> <action name="register" class="mypack.RegisterAction"> <result name="success">/hello.jsp</result> <result name="input">/index.jsp</result> </action> </package> </struts>RegisterAction.javapackage mypack; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport { private String name,password,mailId; @Override public void validate(){ if(name.length()==0) this.addFieldError("name",”Name is Required")); if(password.length()==0) this.addFieldError("password",” Password is Required")); if(password.length()<5) this.addFieldError("password",”Password length more than five digit")); } public String execute(){ return "success"; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getMailId() { return mailId; } public void setMailId(String mailId) { this.mailId = mailId; } }hello.jsp<%@ taglib uri="/struts-tags" prefix="s"%> <b>You are successfully registeredOutput
Previous | Home | Next |