Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.

Slides:



Advertisements
Similar presentations
Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Advertisements

Apache Struts Technology
Web MVC-2: Apache Struts Rimon Mikhaiel
MVC Frameworks Alternatives to coding the MVC pattern.
Struts1 Apache Struts Dr Jim Briggs. Struts2 What is Struts? Struts is an open source framework for building Java web applications Supports MVC/Model.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
An introduction to Java Servlet Programming
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
Point Of Sale(POS) J2EE Application Department : Computer Science Degree : Master Student : Woojin Choi ID : (POS J2EE Application with JRun)
1 Build a Web Application on J2EE. 2 J2EE Scenario Client – Web Server – EIS Resources Client – Web Server – EIS Resources Client – Application Server.
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
Objectives:1. Investigate the Web application deployment descriptor 2. Install and deploy Tomcat and struts 3. Design and deploy a struts application Struts.
Web programming for project students Dr Jim Briggs.
Apache Struts Technology A MVC Framework for Java Web Applications.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Building an application … with Struts! Presented by Ted Husted [ ]
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.
1 Java Database Connection (JDBC) There are many industrial-strength DBMS's commercially available in the market. Oracle, DB2, and Sybase are just a few.
BEST PRACTICES - Java By Configuration Use global-forwards/results Helps to avoid duplicate jsp files and redundancy forward mapping.
Author: DoanNX Version 2.0/Time: 30’. The ways to solve it There are 2 main ways:  Client-side: Using JavaScript (now one very good option is JQuery).
Struts Frameworks Extends Servlet-Controller in a function-specific Action Uses struts-config.xml file to define all function-actions Collects the data.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
Introduction to MVC and the Jakarta Struts Framework By Gyanendra Dwivedi Software Consultant.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Jakarta Struts Presented by Object Computing, Inc. (OCI) Written by Greg Elliott
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,
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Standalone Java Application vs. Java Web Application
8/15/2003System Specialists Corporation How to implement BC4J with the Struts Framework Eugene Sicat Technical Architect/Project Manager System Specialists.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
Fall CIS 764 Database Systems Design L8. Web ….
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.
How to Build a Struts Application with JBuilder 9.
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
J2EE Struts 1 3 Struts: Introduction 1 4 Once you’ve coded a lot of JSP applications, you find yourself doing a lot of repetitive things. Also,
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.
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.
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.
11 Copyright © 2004, Oracle. All rights reserved. Customizing Actions.
Struts Framework Day-2 Ashok Chakravarti. DataSource Usage Sample Struts-config.xml …
Chapter 9 Web Application Design. Objectives Describe the MVC design pattern as used with Web applications Explain the role and responsibilities of each.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
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.
2 Copyright © 2004, Oracle. All rights reserved. ADF Development Process.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
Apache Struts Technology A MVC Framework for Java Web Applications.
CS320 Web and Internet Programming Web Application and MVC Chengyu Sun California State University, Los Angeles.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
V Web Tier Architecture MVC and Struts. v First, there were servlets And things were good Faster than CGI programs More scalable with built-in.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
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.
The Model Layer What is Model?
Struts BY: Tejashri Udavant..
Presentation transcript:

Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation

Tools for this course Tomcat (J2EE server) Ant (build tool) NetBeans (IDE)

A basic web application struts-config.xml in WEB-INF application.properties Several.jar files from Struts and other Jakarta open source projects A modified web.xml, with taglib mappings for the Struts taglibs and possibly JSTL.

Struts MVC with Actions 1. Request is intercepted by controller 2. Form is data captured in an ActionForm 3. Form is data validated in ActionForm 4. Controller calls execute() method of appropriate Action class. 5. Method returns ActionForward of view component.

Struts flow

Important Struts classes ActionForm Capture form data Returns ActionErrors in validate() Action Process the request Forward to appropriate resource Returns ActionForward ActionForward Abstract reference to a resource

The Action class Extend org.apache.struts.action.Action Implement execute() method. Parameters: ActionMapping ActionForm HttpServletRequest HttpServletResponse Thows java.lang.Exception Returns an ActionForward Controller forwards request to this resource.

Standard Actions Struts provides standard Actions ForwardAction SuccessAction FindForwardAction Forwards based on presence of parameter DispatchAction Method executed is determined by parameter Requires code

Action Lab Review JSP pages in application Tasks: Create ActionMappings for JSPs in struts-config.xml Define Actions in struts-config.xml ForwardAction SuccessAction FindForwardAction Create a subclass of DispatchAction

ActionForms ActionForms are used to collect and validate data from a request, typically generated by an HTML form. ActionForms resemble Java beans. Getters and setters Both not required Setters can expose data to inadvertent/malicious manipulation

ActionForm validation ActionForms have a validate() method. If validation is requested, this method is called after the ActionForm is populated with the request data. The validate() method returns an ActionErrors object, which is a collection of error messages If form validation fails, the request is forwarded back to the input form. Failure is determined by the presence of one or more ActionError objects in the ActionErrors collection. If the input form was constructed using the appropriate Struts tags, the form data is filled in. The Struts taglib can be used to display ActionError messages to the user.

ActionErrors The application.properties file defines the application ’ s error messages. error.userid.required=You must enter a user id Using the ActionErrors ActionErrors errors = new ActionErrors(); errors.add ("userid", new ActionError("error.userid.required")); Use a tag on the JSP page containing the input form

ActionForm lab Augment the FindForwardAction from Lab 1 with an Action that checks the user id and password Action will forward to warning page if credentials are not valid Create an ActionForm that will validate the login form data Validation should fail if user id or password is blank

Database access Access to a database requires a Connection. Web applications require many concurrent DB connections Opening a DB connection is slow Connection pooling Request a Connection from the pool Use the Connection Return the Connection to the pool

Where to put the pool? Persistence code needs access to the connection pool Where should the application store the pool? The web application ’ s application scope? Object with static members JNDI

Directory context Java objects Referenced by name javax.naming.* Naming Aliases java:comp/env/jdbc/mydb

JNDI setup Modify Tomcat ’ s server.xml file Commercial servers usually have web interface to create connection pools Modify web.xml file Add element Other J2EE servers may require an additional XML file.

Using JNDI Get InitialContext object InitialContext ic = new InitialContext() Look up the DataSource object Object o = ic.lookup( “ java:comp/env/jdbc/mydb ” ); Cast the object to the required class DataSource ds = (DataSource) o; Combine the lookup and the cast in one line for more compact code. Context operations will throw javax.naming.NamingException

JNDI Lab Check that necessary JAR files are in Tomcat ’ s common/lib directory Modify Tomcat ’ s server.xml Set correct DB URL Set password and username Modify web application ’ s web.xml Edit index.jsp Edit SQL query Add code to fetch data from ResultSet Add code to display data