Struts 2 Actions By, Srinivas Reddy.S www.JAVA9S.com.

Slides:



Advertisements
Similar presentations
Servlets & JSPs - Sharad Ballepu.
Advertisements

Java Control Statements
May 13th, Lucek Consulting Basic Java Servlet/JSP Web Development David Lucek Lucek Consulting
Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from.
JSP and web applications
Pure Struts web-application header.jsp footer.jsp menu.jsp body … + mybody.jsp layout.jsp struts-config.xml tiles-def.xml classical include in servlet.
Struts Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Struts Portlet Adding an Action Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without.
Spring 3.0 MVC - Introduction By, Srinivas Reddy.S
JSF Portlet Backing Beans and UI Components Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in.
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
CS4273: Distributed System Technologies and Programming I Lecture 11: JavaServer Pages (JSP)
Apache Struts Technology
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
@mnriem#DV14 #MVC MVC 1.0 in JavaEE 8 A long time coming, or like some would say “finally!” Why are we doing it now? Survey input Customer input JavaEE.
Servlets Enterprise Systems Programming. Servlets  Servlets: server-side Java programs that enable dynamic processing of web-based requests  Web-based.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Web MVC-2: Apache Struts Rimon Mikhaiel
© 2006 by IBM and Naci Dai; made available under the EPL v1.0 | Santa Clara | Mar. 20, 2006 Java™ Web Application Development with Eclipse WTP - WTP Quick.
Tutorial: Server-Side Web Applications with Java, JSP and Tomcat Eran Toch December 2004 Methodologies in Information Systems Development.
JEditorPane Chapter 18 - Student. (c) 2005 by Elizabeth Sugar Boese JEditorPane creation Declare a JEditorPane component. JEditorPane pane; Check to see.
Session-01. Layers Struts 2 Framework The struts 2 framework is used to develop MVC-based web application. Struts 1.0 was released in June The.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Struts 2.0 an Overview ( )
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
UNIT-V The MVC architecture and Struts Framework.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
JSP and Servlets Lecture notes by Theodoros Anagnostopoulos.
WebWork in Action An introduction to WebWork Patrick A. Lightbody.
Welcome to Library Management System
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
Basic Struts Architecture Client Server Database Request Response Control View Model Server Struts Framework.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
JBoss Seam Presented by Andy Nguyen Truc Pham. What is JBoss Seam? Created by Gavin King Created by Gavin King A lightweight framework for Java EE 5.0.
Mark Dixon 1 12 – Java Beans. Mark Dixon 2 Session Aims & Objectives Aims –To cover the use of Java Beans Objectives, by end of this week’s sessions,
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
How to Build a Struts Application with JBuilder 9.
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Chapter 2 An Overview of Servlet and JSP Technology.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.jsp.
Blackboard Building Blocks Portal Modules and Module Types Monday, November 16, 2015 Tom Joyce, Product Manager, Product Development.
Struts 2 introduction. Struts 2 framework Struts 2 A full-featured web application framework for the Java EE platform The Java Servlet API exposes the.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
JSP Custom Tags. Prerequisites Servlet API Mapping to JSP implicit objects JavaServer Pages Basic syntax Implementation via servlet API XML.
1 Command Processor II. 2 Command Processor Example Let's look at a simple example of a command processor using states and cities. Get initial information.
Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 1 Struts2 Reinventing Struts1 Wheel Ori Dar Consultant and Architect, AlphaCSP.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
Core basic Java web server technologies. Tools Eclipse IDE for Java EE Developers (Netbeans also works) nloads/packages/eclipse-
© 2006 by IBM and Naci Dai; made available under the EPL v1.0 | Santa Clara | Mar. 20, 2006 Java™ Web Application Development with Eclipse WTP - WTP Quick.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
Struts 2 Introduction.
Portal Modules & Module Types Heather Natour Senior Software Engineer, Blackboard Community System.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
Chapter 2 Java Struct 2. Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Popup Boxes.
Apache Struts Technology A MVC Framework for Java Web Applications.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Struts Zero Configuration Struts University Series.
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Unit 6-Chapter 2 Struts.
Add Image and Title to Individual Page
Introduction to Java Servlets
Presentation transcript:

Struts 2 Actions By, Srinivas Reddy.S

Agenda Action and its role Packages and namespaces Results Action and ActionSupport Using wildcards

A Simple Birthday Action URL: When accessed, a page asking for the persons name should be displayed URL: This displays the success page which greets the person.

Step 1: Create a JSP: birthday.jsp Enter the Birthday Boys name: A Simple Birthday Action

A Simple Birthday Action Step 2: Create an Action class to handle the form HappyBirthday.java package greetings; public class HappyBirthday { private String birthdayBoy; public String execute(){ if(this.getBirthdayBoy().equals()||this.getBirthdayBoy()==null){ return failure"; }else{ return SUCCESS"; } public String getBirthdayBoy() { return birthdayBoy; } public void setBirthdayBoy(String birthdayBoy) { this.birthdayBoy = birthdayBoy; }

A Simple Birthday Action Step 3: Create the Success and failure JSPs birthdaySuccess.jsp Wish you a Very Happy Birthday to You :-) noBirthday.jsp LOOKS LIKE NO BODY IS CELEBRATING BIRTHDAY TODAY

A Simple Birthday Action Step 4: Configure the Struts.xml /pages/birthday.jsp /pages/birthdaySuccess.jsp /pages/noBirthday.jsp Note: Struts.xml should be in WEB-INF/classes folder

Role of Action Controller Data carrier Result to be invoked

Action as Controller public String execute(){ if(this.getBirthdayBoy().equals()||this.getBirthdayBoy()==null){ return failure"; }else{ BirthdayUtil.calculateAge(birthDate); Other business layer or service layer return SUCCESS"; } }

Action as Data Carrier public class HappyBirthday { A simple POJO private String birthdayBoy; public String getBirthdayBoy() { return birthdayBoy; } public void setBirthdayBoy(String birthdayBoy) { this.birthdayBoy = birthdayBoy; }

Action as Result render public String execute(){ if(this.getBirthdayBoy().equals()||this.getBirthdayBoy()==null){ return failure"; }else{ return SUCCESS"; } } /pages/birthdaySuccess.jsp /pages/noBirthday.jsp

No execute() method You can specify a different method other than execute method to play as controller method. <action name ="happybirthday" class ="greetings.HappyBirthday method =wishForBirthday > /pages/birthdaySuccess.jsp /pages/noBirthday.jsp

Packages and Namespaces /pages/birthday.jsp /pages/birthdaySuccess.jsp /pages/noBirthday.jsp

Note: – Package name is mandatory. – namespace is optional but the default is /. – extends – to extend a parent package. abstract- If true, this package will only be used to define inheritable components, not actions Packages and Namespaces

Result and types JSP Velocity Freemarker Xslt Text Stream

Result and types /pages/birthdaySuccess.jsp /pages/noBirthday.jsp Attributes: name – should match with the return string from the execute method. Default is SUCCESS type – chain, dispatcher, freemarker, httpheader, redirect, redirectAction, stream, velocity, xslt, plaintext, tiles

Action Interface

ActionSupport class Implements the interfaces Action, LocaleProvider, TextProvider, Validateable, ValidationAware, Serializable Supports Internationalization. Supports Programmatic validation.

ModelDriven Interface Used to tell that the form details to be filled to a different POJO instead of Action class itself. Eg., public class Login implements ModelDriven{ private User user = new User(); public Object getModel(){ return user; } }

Using Wildcards /WEB-INF/jsps/{1}.jsp URL: /WEB-INF/jsps/testwildcard.jsp

/WEB-INF/jsps/{1}/{2}.jsp URL: /WEB-INF/jsps/test/testwildcard.jsp Using Wildcards

External configuration files Struts.xml

Thank you Download this PPT and example code from