Session-02. Index. Jsp in Struts 2 Web.xml File in Struts 2.

Slides:



Advertisements
Similar presentations
Struts 2.0.
Advertisements

Apache Struts Technology
Struts 2 Interceptors By, Srinivas Reddy.S
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
DT228/3 Web Development JSP: Directives and Scripting elements.
MC365 Application Servers: Java Server Pages (JSP’s) and Session Management.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Apache Struts Technology A MVC Framework for Java Web Applications.
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.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Struts 2.0 an Overview ( )
Introduction to Struts 2.0 Jenny Ni Joey Feng Winddays Wang Hewmmi Zhu Heather Lv Software School,Fudan University 1.
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages (JSP) Presented by: Ananth Prasad & Alex Ivanov May 10, 2001.
WebWork in Action An introduction to WebWork Patrick A. Lightbody.
Java Frameworks Indy Java Users Group January 29, 2003.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Pittsburgh Java User Group– Dec Java PureFaces: A JSF Framework Extension.
BEST PRACTICES - Java By Configuration Use global-forwards/results Helps to avoid duplicate jsp files and redundancy forward mapping.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
JSP Java Server Pages Softsmith Infotech.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Basic Struts Architecture Client Server Database Request Response Control View Model Server Struts Framework.
Struts2 Plugin Development - Extending Struts2 Justin Yip.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 5 JavaServer Faces (JSF) Technology.
JAVA SERVER FACES ADITI RAJORIYA UNI – ar2630. POINTS TO BE DISSCUSED WHAT IS JSF? WHY JSF? ARCHITECTURE JSF VERSIONS UI COMPONENTS JSF STRUCTURE AND.
1 MSCS 237 Overview of web technologies (A specific type of distributed systems)
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
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.
REVOLUTION TO NEXT GENERATION Struts2.0 20/02/ Avishek Arang ::
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
2006/2007 Licence Apache 2.0 Castle.Igloo. Castle Igloo Basics Pre-require Concept Scopes PageFlow Configuration Controller View Exemple Castle.Igloo.
Struts 2 Introduction.
Data transfer and type conversion One of the common tasks of the web application domain was moving and converting data from string-based HTTP to the various.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
Singleton Academy, Pune. Course syllabus Singleton Academy Pune – Course Syllabus1.
Chapter 2 Java Struct 2. Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture.
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Apache Struts Technology A MVC Framework for Java Web Applications.
Model View Controller. MVC is the separation of model, view and controller. It's simply a paradigm; an ideal that you should have in the back of your.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Best Struts 2 Training By TOPS Technologies.
Java Servlets.
Introduction to Struts
The Model Layer What is Model?
Objectives In this lesson you will learn about: Need for servlets
Presentation transcript:

Session-02

Index. Jsp in Struts 2

Web.xml File in Struts 2

Action Class in Struts 2

Struts.xml in Struts 2

View in Struts 2

Struts 2 disadvantages 1.Bigger learning curve 2.Poor documentation 3.Less transparent

Core Components 1.Struts 2 Interceptors 2.Struts 2 ValueStack 3.Struts 2 ActionContext 4.Struts 2 ActionInvocation 5.Struts 2 OGNL

1) Struts 2 Interceptors InterceptorInterceptor is an object that is invoked at the preprocessing and postprocessing of a request. InterceptorsInterceptors are the backbone of Struts2 Framework. Struts2 interceptorsStruts2 interceptors are responsible for most of the processing done by the framework, such as passing request params to action classes, making Servlet API request, response, session available to Action classes, validation, i18n support, etc. In Struts 2, interceptor is used to perform operations such as validation, exception handling, internationalization, displaying intermediate result etc. ActionInvocationActionInvocation is responsible to encapsulate Action classes and interceptors and to fire them in order. The most important method for use in ActionInvocation is invoke() method that keeps track of the interceptor chain and invokes the next interceptor or action.

Advantage of interceptors Pluggable If we need to remove any concern such as validation, exception handling, logging etc. from the application, we don't need to redeploy the application. We only need to remove the entry from the struts.xml file.

Struts 2 default interceptors

Example

Example Explanation

Interceptor Class

How to use Interceptors?

Create Interceptor Class

Create Action Class

Struts.xml

OUTPUT

Does interceptors is thread safe? Struts2 interceptors are singleton classes and a new thread is created to handle the request, So it’s not thread safe and we need to implement them carefully to avoid any issues with shared data.

Which class is the Front Controller in Struts2?

Stacking multiple Interceptors As you can imagine, having to configure multiple interceptor for each action would quickly become extremely unmanageable. For this reason, interceptors are managed with interceptor stacks. Here is an example, directly from the struts-default. xml file:

How to Use basicStack ? We have already seen how to apply interceptor to the action, applying interceptor stacks is no different. In fact, we use exactly the same tag:

What is the use of execAndWait interceptor? Sometimes we have long running actions where user will have to wait for final result. In this case, user can get annoyed with no response and may refresh the page causing issues in application. Struts2 provide execAndWait interceptor that we can use for long running action classes to return an intermediate result to user while the processing is happening at server side. Once the processing is finished, user will be presented with the final result page. Struts2 execAndWait interceptor is already defined in the struts-default package and we just need to configure it for our action classes. The implementation is present in ExecuteAndWaitInterceptor class that returns “wait” result page until the processing of action class is finished.

Mostly used Interceptors

2) Struts 2 ValueStack A valueStack is simply a stack that contains application specific objects such as action objects and other model object. At the execution time, action is placed on the top of the stack. We can put objects in the valuestack, query it and delete it.

Dynamic data handling using Struts 2 ValueStack

Continue… ValueStack, one of the powerful features of Struts 2, holds all the data during processing of a request. Action classes also store data in the form of beans. (In Struts 2 you use getter and setter methods.) Once the data is stored in the action class objects, Struts 2 puts that data onto the ValueStack in the form of the Action object. ValueStack stores a stack of objects, and this data will be exposed to the other parts of the framework.

How does ValueStack in Struts2 work? Struts2 puts in the stack are not the properties, but the objects that hold those properties.

Static data versus dynamic data If data that will be displayed on the UI is known in advance, it can be called static data. Static data can be handled easily by coding it directly in JavaServer Pages (JSP).

Static data versus dynamic data

Continue… The value stack is a set of several objects which keeps the following objects in the provided order: you can get valueStack object inside your action as follows:

3) Struts 2 ActionContext The ActionContext is a container of objects in which action is executed. The values stored in the ActionContext are unique per thread (i.e. Thread Local). So we don't need to make our action thread safe. The struts framework places other objects in ActionContext also e.g. map representing the request, session, application scopes.

Struts 2 ActionContext Class

4) Struts 2 ActionInvocation The ActionInvocation represents the execution state of an action. It holds the action and interceptors objects.

Struts 2 ActionInvocation Class

Example

5) Struts 2 OGNL The Object Graph Navigation Language (OGNL) is an expression language. It simplifies the accessibility of data stored in the ActionContext. OGNL also helps in data transfer and type conversion. The struts framework sets the ValueStack as the root object of OGNL. Notice that action object is pushed into the ValueStack. We can direct access the action property.

Role of OGNL in Struts 2

Continue… The struts framework places other objects in ActionContext also e.g. map representing the request, session, application scopes. To get these values i.e. not the action property, we need to use # notation. #sessionFor example to get the data from session scope, we need to use #session as given in the following example:

Continue…

Summary!!