Chapter 2 Java Struct 2. Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture.

Slides:



Advertisements
Similar presentations
Struts 2.0.
Advertisements

Apache Struts Technology
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Struts 2 Interceptors By, Srinivas Reddy.S
Web MVC-2: Apache Struts Rimon Mikhaiel
Struts1 Apache Struts Dr Jim Briggs. Struts2 What is Struts? Struts is an open source framework for building Java web applications Supports MVC/Model.
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
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.
Session-02. Index. Jsp in Struts 2 Web.xml File in Struts 2.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Stateful Web Application Development with Spring Web Flow John Case Senior Consultant Centare Group, Ltd.
1 Guide to JSP common functions 1.Including the libraries as per a Java class, e.g. not having to refer to java.util.Date 2.Accessing & using external.
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.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
WebWork in Action An introduction to WebWork Patrick A. Lightbody.
Welcome to Library Management System
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
® IBM Software Group © 2007 IBM Corporation JSP Custom Tags
Introduction to Java Server Pages (JSPs) Robert Thornton.
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 Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
JSP Architecture Outline  Model 1 Architecture  Model 2 Architecture.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Standalone Java Application vs. Java Web Application
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
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.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Java Server Pages (JSP)
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
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
Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.
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.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
Team Members Tyler Lamb Kirk Olson James Woestman IRP Presentation Client Zirous Inc. Faculty Advisor Tien Nguyen 1.
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.
Chapter 9 Web Application Design. Objectives Describe the MVC design pattern as used with Web applications Explain the role and responsibilities of each.
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.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
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.
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.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Unit 6-Chapter 2 Struts.
Introduction to Struts
The Model Layer What is Model?
Add Image and Title to Individual Page
Struts BY: Tejashri Udavant..
Presentation transcript:

Chapter 2 Java Struct 2

Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture

Basic MVC Architecture Model - The lowest level of the pattern which is responsible for maintaining data. View - This is responsible for displaying all or a portion of the data to the user. Controller - Software Code that controls the interactions between the Model and View.

Struts 2 Overview Struts 2 framework features: – POJO forms and POJO actions - With Struts2, you can use any POJO to receive the form input. Similarly, you can now see any POJO as an Action class. – Tag support - Struts2 has improved the form tags and the new tags allow the developers to write less code. – AJAX support - Struts2 has recognised the take over by Web2.0 technologies, and has integrated AJAX support into the product by creating AJAX tags, that function very similar to the standard Struts2 tags. – Easy Integration - Integration with other frameworks like Spring, Tiles and SiteMesh is now easier with a variety of integration available with Struts2. – Template Support - Support for generating views using templates. – Plugin Support - The core Struts2 behaviour can be enhanced and augmented by the use of plugins. A number of plugins are available for Struts2. – Profiling - Struts2 offers integrated profiling to debug and profile the application. – Easy to modify tags - Tag markups in Struts2 can be tweaked using Freemarker templates. – Promote less configuration - Struts2 promotes less configuration with the help of using default values for various settings. – View Technologies: - Struts2 has a great support for multiple view options (JSP, Freemarker, Velocity and XSLT)

Struts 2 - Architecture Actions: It plays an important role in the transfer of data from the request through to the view and assist the framework in determining which result should render the view that will be returned in the response to the request. Interceptors: It providing preprocessing logic before/ after the action is called and catching exceptions. Value Stack / OGNL: It is a set of several objects which keeps the following objects in the provided order(Temporary, Model, Action, Named) Results / Result types View technologies

Example Component for create Hello example: – Action Create an action class which will contain complete business logic and control the interaction between the user, the model, and the view. – Interceptors: This is part of Controller. – View Create a JSPs to interact with the user to take input and to present the final messages. – Configuration Files Create configuration files to couple the Action, View and Controllers. These files are struts.xml, web.xml, struts.properties.

Create Action Class HelloWorldAction.java public class HelloWorldAction{ private String name; public String execute() throws Exception { return "success"; } public String getName() { return name; } public void setName(String name) { this.name = name; }

Create a View HelloWorld.jsp Hello World Hello World,

Create main page index.jsp page language="java" contentType="text/html; charset=ISO " pageEncoding="ISO "%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " Hello World Hello World From Struts2 Please enter your name

Configuration Files struts.xml <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" " <action name="hello" class="com.tutorialspoint.struts2.HelloWorldAction" method="execute"> /HelloWorld.jsp

Configuration Files web.xml <web-app xmlns:xsi=" xmlns=" xmlns:web=" xsi:schemaLocation=" id="WebApp_ID" version="3.0"> Struts 2 index.jsp struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /*

Action Feature of Action Class: – Inherit from ActionSupport class. – It contains execute() method for process. After execute method was call by struct2 it return as result type. – We can create multiple action. Result Type: – SUCCESS = "success“ – NONE = "none” – ERROR = "error” – INPUT = "input” – LOGIN = "login"

Interceptor Feature of Interceptor: – Providing pre processing logic before action call. – Providing post processing logic after the action call. – Catching exception Framework Interceptors – alias Allows parameters to have different name aliases across requests. – checkbox Assists in managing check boxes by adding a parameter value of false for check boxes that are not checked. – conversionError Places error information from converting strings to parameter types into the action's field errors. – createSession Automatically creates an HTTP session if one does not already exist. – debugging Provides several different debugging screens to the developer. – execAndWait Sends the user to an intermediary waiting page while the action executes in the background. – exception Maps exceptions that are thrown from an action to a result, allowing automatic exception handling via redirection. – fileUpload Facilitates easy file uploading. – params Sets the request parameters on the action. – prepare This is typically used to do pre-processing work, such as setup database connections. – timer Provides simple profiling information in the form of how long the action takes to execute. – validation Provides validation support for actions. How to use Interceptor: – put it in structs.xml Create Custom Interceptor: – Component for using: AbstractInterceptor abstract class and ActionInvocation object. – Step for create custom interceptor: Step 1 : Create Interceptor Class by inherit from AbstractItnerceptor class. Step 2 : Adding Overriding method intercept() in interceptor class Step 3 : Calling Invoke Method of ActionInvocation object Step 4 : Write Configuration file Structs.xml

Example MyInterceptor.java public class MyInterceptor extends AbstractInterceptor { public String intercept(ActionInvocation invocation)throws Exception{ /* let us do some pre-processing */ String output = "Pre-Processing"; System.out.println(output); /* let us call action or next interceptor */ String result = invocation.invoke(); /* let us do some post-processing */ output = "Post-Processing"; System.out.println(output); return result; }

Example HelloWorldAction.java(Action) public class HelloWorldAction extends ActionSupport{ private String name; public String execute() throws Exception { System.out.println("Inside action...."); return "success"; } public String getName() { return name; } public void setName(String name) { this.name = name; }

Example Structs.xml <interceptor name="myinterceptor" class="MyInterceptor" /> <action name="hello" class="com.tutorialspoint.struts2.HelloWorldAction" method="execute"> /HelloWorld.jsp

Value Stack/OGNL Value Stack object: – Temporary Objects There are various temporary objects which are created during execution of a page. – The Model Object If you are using model objects in your struts application, the current model object is placed before the action on the value stack – The Action Object This will be the current action object which is being executed. – Named Objects These objects include #application, #session, #request, #attr and #parameters and refer to the corresponding servlet scopes How to access ValueStack object: – ActionContext.getContext().getValueStack() Value Stack Method: – Object findValue(String expr) Find a value by evaluating the given expression against the stack in the default search order. – void set(String key, Object o) Sets an object on the stack with the given key so it is retrievable by findValue(key,...) – void setValue(String expr, Object value) Attempts to set a property on a bean in the stack with the given expression using the default search order. OGNL: It is used to reference and manipulate data on the value stack(help data transfer and type conversion). ActionContext map consists of : – application - application scoped variables. – session - session scoped variables. – request - request scoped variables. – parameters - request parameters. – atributes - the attributes stored in page, request, session and application scope. Note: – Object in ActionContext using pound symbol(“#name”) – Object in ValueStack do not using pound symbol(“name”) <s:Select name=“name” list=“{‘V1’, ’V2’, ’V3’}

Example public class HelloWorldAction extends ActionSupport{ private String name; public String execute() throws Exception { ValueStack stack = ActionContext.getContext().getValueStack(); Map context = new HashMap (); context.put("key1", new String("This is key1")); context.put("key2", new String("This is key2")); stack.push(context); System.out.println("Size of the valueStack: " + stack.size()); return "success"; } public String getName() { return name; } public void setName(String name) { this.name = name; }

Example HelloWorld.jsp Hello World Entered value : Value of key 1 : Value of key 2 :

Exception Handling HelloWorldAction.java(Action) public class HelloWorldAction extends ActionSupport{ private String name; public String execute(){ String x = null; x = x.substring(0); return SUCCESS; } public String getName() { return name; } public void setName(String name) { this.name = name; }

Exception Handling Helloworld.jsp(View) Hello World Hello World,

Exception Handling Error.jsp page language="java" contentType="text/html; charset=ISO " pageEncoding="ISO "%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " This is my custom error page

Exception Handling Structs.xml <exception-mapping exception="java.lang.NullPointerException" result="error" /> <action name="hello" class="com.tutorialspoint.struts2.HelloWorldAction" method="execute"> /HelloWorld.jsp /Error.jsp