Introduction to Struts
www.collaborationtech.co.in
Bengaluru INDIA
Presentation By
Ramananda M.S Rao
Content
Content
Overview
Get Started
STR UTS 1.X
STR UTS 2
Struts2 Configuration
Interceptors
Struts 2 & Ajax Validation
Struts2 with I18N
About Us
www.collaborationtech.co.in
Overview
 Struts2 is popular and mature web application framework based
on the MVC design pattern. Struts2 is not just the next version of
Struts 1, but it is a complete rewrite of the Struts architecture.
 Struts2 supports annotation based configurations which are easy
to create and more intuitive. Action class in Struts 2 act as the
model in the web application. Unlike Struts 1.X, Struts 2 Action
class are plain POJO objects, thus simplifying the testing of the
code.
 Struts2 also comes with power APIs to configure Interceptors that
reduce greatly the coupling in application. The view part of Struts 2
is highly configurable and it supports different result-types such as
Velocity, FreeMarker, JSP, etc.
www.collaborationtech.co.in
Struts 2 - Validation
Register.java
package collaba.validation;
import com.opensymphony.xwork2.ActionSupport;
public class Register extends ActionSupport{
private String name,password,email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
www.collaborationtech.co.in
Struts 2 - Validation
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute(){
return "success";
}
}
Register-validation.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
www.collaborationtech.co.in
Struts 2 - Validation
<validators>
<field name="name">
<field-validator type="requiredstring">
<message>Name can't be blank</message>
</field-validator>
</field>
<field name="email">
<field-validator type="requiredstring">
<message>Email ID can't be blank</message>
</field-validator>
<field-validator type="email">
<message>Please enter a valid email ID</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message>Password can't be blank</message>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">5</param>
<param name="maxLength">10</param>
<message>Password can't be less than 5 or greater than 10</message>
</field-validator>
</field>
</validators>
www.collaborationtech.co.in
Struts 2 - Validation
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="a" extends="struts-default">
<action name="register" class="collaba.validation.Register">
<interceptor-ref name="jsonValidationWorkflowStack"></interceptor-ref>
<result name="success">/welcome.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
</struts>
www.collaborationtech.co.in
Struts 2 - Validation
WEB-INF
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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>
www.collaborationtech.co.in
Struts 2 - Validation
index.jsp
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="/struts-dojo-tags" prefix="d"%>
<html>
<head>
<d:head/>
</head>
<body><marquee>Registration Page.............</marquee>
<s:form action="register">
<s:textfield name="name" label="Username"></s:textfield>
<s:textfield name="email" label="Email ID"></s:textfield>
<s:password name="password" label="Password"></s:password>
<d:submit validate="true" type="image" src="reg.jpg"></d:submit>
</s:form>
</body>
</html>
welcome.jsp
<%@ taglib uri="/struts-tags" prefix="s" %>
Welcome, <s:property value="name"/>
www.collaborationtech.co.in
Follow us on Social
Facebook: https://www.facebook.com/collaborationtechnologies/
Twitter : https://twitter.com/collaboration09
Google Plus : https://plus.google.com/100704494006819853579
LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545
Instagram : https://instagram.com/collaborationtechnologies
YouTube :
https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg
Skype : facebook:ramananda.rao.7
WhatsApp : +91 9886272445
www.collaborationtech.co.in
THANK YOU
About Us

Introduction to Struts 2

  • 1.
    Introduction to Struts www.collaborationtech.co.in BengaluruINDIA Presentation By Ramananda M.S Rao
  • 2.
    Content Content Overview Get Started STR UTS1.X STR UTS 2 Struts2 Configuration Interceptors Struts 2 & Ajax Validation Struts2 with I18N About Us www.collaborationtech.co.in
  • 3.
    Overview  Struts2 ispopular and mature web application framework based on the MVC design pattern. Struts2 is not just the next version of Struts 1, but it is a complete rewrite of the Struts architecture.  Struts2 supports annotation based configurations which are easy to create and more intuitive. Action class in Struts 2 act as the model in the web application. Unlike Struts 1.X, Struts 2 Action class are plain POJO objects, thus simplifying the testing of the code.  Struts2 also comes with power APIs to configure Interceptors that reduce greatly the coupling in application. The view part of Struts 2 is highly configurable and it supports different result-types such as Velocity, FreeMarker, JSP, etc. www.collaborationtech.co.in
  • 4.
    Struts 2 -Validation Register.java package collaba.validation; import com.opensymphony.xwork2.ActionSupport; public class Register extends ActionSupport{ private String name,password,email; public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getName() { return name; } www.collaborationtech.co.in
  • 5.
    Struts 2 -Validation public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String execute(){ return "success"; } } Register-validation.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> www.collaborationtech.co.in
  • 6.
    Struts 2 -Validation <validators> <field name="name"> <field-validator type="requiredstring"> <message>Name can't be blank</message> </field-validator> </field> <field name="email"> <field-validator type="requiredstring"> <message>Email ID can't be blank</message> </field-validator> <field-validator type="email"> <message>Please enter a valid email ID</message> </field-validator> </field> <field name="password"> <field-validator type="requiredstring"> <message>Password can't be blank</message> </field-validator> <field-validator type="stringlength"> <param name="minLength">5</param> <param name="maxLength">10</param> <message>Password can't be less than 5 or greater than 10</message> </field-validator> </field> </validators> www.collaborationtech.co.in
  • 7.
    Struts 2 -Validation struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="a" extends="struts-default"> <action name="register" class="collaba.validation.Register"> <interceptor-ref name="jsonValidationWorkflowStack"></interceptor-ref> <result name="success">/welcome.jsp</result> <result name="input">/index.jsp</result> </action> </package> </struts> www.collaborationtech.co.in
  • 8.
    Struts 2 -Validation WEB-INF 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"> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app> www.collaborationtech.co.in
  • 9.
    Struts 2 -Validation index.jsp <%@ taglib uri="/struts-tags" prefix="s"%> <%@ taglib uri="/struts-dojo-tags" prefix="d"%> <html> <head> <d:head/> </head> <body><marquee>Registration Page.............</marquee> <s:form action="register"> <s:textfield name="name" label="Username"></s:textfield> <s:textfield name="email" label="Email ID"></s:textfield> <s:password name="password" label="Password"></s:password> <d:submit validate="true" type="image" src="reg.jpg"></d:submit> </s:form> </body> </html> welcome.jsp <%@ taglib uri="/struts-tags" prefix="s" %> Welcome, <s:property value="name"/> www.collaborationtech.co.in
  • 10.
    Follow us onSocial Facebook: https://www.facebook.com/collaborationtechnologies/ Twitter : https://twitter.com/collaboration09 Google Plus : https://plus.google.com/100704494006819853579 LinkedIn : https://www.linkedin.com/in/ramananda-rao-a2012545 Instagram : https://instagram.com/collaborationtechnologies YouTube : https://www.youtube.com/channel/UCm9nK56LRbWSqcYWbzs8CUg Skype : facebook:ramananda.rao.7 WhatsApp : +91 9886272445 www.collaborationtech.co.in THANK YOU
  • 11.