Jakarta Struts: An MVC Framework

Similar documents
Jakarta Struts: An MVC Framework

JSF: Introduction, Installation, and Setup

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

Building Web Applications With The Struts Framework

Servlet and JSP Review

112. Introduction to JSP

Model View Controller (MVC)

Jakarta Struts. Pocket Reference. Chuck Cavaness and Brian Keeton. Beijing Boston Farnham Sebastopol Tokyo

112-WL. Introduction to JSP with WebLogic

Struts: A Quick Installation Guide

Web Application Architecture (based J2EE 1.4 Tutorial)

JavaEE Interview Prep

Experiment No: Group B_2

Integrating Servlets and JavaServer Pages Lecture 13

servlets and Java JSP murach s (Chapter 2) TRAINING & REFERENCE Mike Murach & Associates Andrea Steelman Joel Murach

CSC 8205 Advanced Java

SECTION II: JAVA SERVLETS

One application has servlet context(s).

Setup and Getting Startedt Customized Java EE Training:

CS506 Web Design & Development Final Term Solved MCQs with Reference

CHAPTER 6. Organizing Your Development Project. All right, guys! It s time to clean up this town!

Free Downloads Java Servlet & JSP Cookbook

Hackveda Appsec Labs Java Programming Course and Internship Program Description:

Module 5 Developing with JavaServer Pages Technology

Ch04 JavaServer Pages (JSP)

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

For live Java EE training, please see training courses at

Developing Applications with Java EE 6 on WebLogic Server 12c

Java with Eclipse: Setup & Getting Started

The Spring Framework: Overview and Setup

Setting Up the Development Environment

Directory structure and development environment set up

About the Authors. Who Should Read This Book. How This Book Is Organized

Topics Augmenting Application.cfm with Filters. What a filter can do. What s a filter? What s it got to do with. Isn t it a java thing?

Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat

Advantage of JSP over Servlet

Jakarta Struts: Declarative Exception Handling

Fast Track to Java EE

JAVA SERVLET PROGRAMMING HELP FOR SERVER SIDE JAVA DEVELOPERS JAVA SERIES

Fast Track to Java EE 5 with Servlets, JSP & JDBC

UIMA Simple Server User Guide

JSF Tools Reference Guide. Version: M5

Introduction to JSP and Servlets Training 5-days

Customizing Oracle Identity Governance: Populating Request Attributes

ADVANCED JAVA COURSE CURRICULUM

J2EE Interview Questions

Getting started with Apache Struts 2, with Netbeans 6.1

Contents at a Glance

SUN Enterprise Development with iplanet Application Server

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

FINALTERM EXAMINATION Spring 2009 CS506- Web Design and Development Solved by Tahseen Anwar

NetBeans IDE Field Guide

CodeCharge Studio Java Deployment Guide Table of contents

1 CUSTOM TAG FUNDAMENTALS PREFACE... xiii. ACKNOWLEDGMENTS... xix. Using Custom Tags The JSP File 5. Defining Custom Tags The TLD 6

Rational Application Developer 7 Bootcamp

LTBP INDUSTRIAL TRAINING INSTITUTE

DVS WEB INFOTECH DEVELOPMENT TRAINING RESEARCH CENTER

An Integrated Approach to Managing Windchill Customizations. Todd Baltes Lead PLM Technical Architect SRAM

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC.

Webservices In Java Tutorial For Beginners Using Netbeans Pdf

Java Programming Language

JAVA 2 ENTERPRISE EDITION (J2EE)

MyLEAD Release V1.3 Installation Guide

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

SOCIAL NETWORKING WEB APPLICATION USING STRUTS FRAMEWORK

Author - Ashfaque Ahmed

HYPERION SYSTEM 9 BI+ GETTING STARTED GUIDE APPLICATION BUILDER J2EE RELEASE 9.2

DESIGN AND IMPLEMENTATION OF SAGE DISPLAY CONTROLLER PROJECT

114. Jakarta Struts. Prerequisites. Version 1.1.3

Module 3 Web Component

Java Server Page (JSP)

Contents. 1. JSF overview. 2. JSF example

LTBP INDUSTRIAL TRAINING INSTITUTE

J2SE, JSP & JavaBeans Web Demonstration of SWKB Program

JBoss Web Framework Kit 1.0 Release Notes

JSF Tools Reference Guide. Version: beta1

Designing a Distributed System

COMP9321 Web Application Engineering

Web-based IDE for Interfacing View Controller

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Spring Web Services Tutorial With Example In

A web application serving queries on renewable energy sources and energy management topics database, built on JSP technology

In this Tutorial we present tips and trick for the development enviroment eclipse and the extension MyEclipse.

Introduction to Java Server Faces(JSF)

A Model-Controller Interface for Struts-Based Web Applications

Setting up a Maven Project

COMP9321 Web Application Engineering

J2EE for Oracle Technologists

Introduction to Java Server Pages. Enabling Technologies - Plug-ins Scripted Pages

BlueDragon TM 7.0 Deploying CFML on J2EE Application Servers

IBM Rational Application Developer for WebSphere Software, Version 7.0

Liferay Portal 4 - Development in the Extension Environment. Joseph Shum Alexander Chow Redmond Mar Jorge Ferrer

BlueDragon TM 3.0 Deploying CFML on J2EE Servers

COURSE DETAILS: CORE AND ADVANCE JAVA Core Java

AN ISO 9001:2008 CERTIFIED COMPANY ADVANCED. Java TRAINING.

Enterprise Java Unit 1- Chapter 3 Prof. Sujata Rizal Introduction to Servlets

ZK Mobile The Quick Start Guide

CHAPTER. Introduction to the Oracle Application Development Framework

GUJARAT TECHNOLOGICAL UNIVERSITY

ArcIMS 9. Customizing ArcIMS Using the Java Connector. GIS by ESRI

Transcription:

Jakarta Struts: An MVC Framework Overview, Installation, and Setup. Struts 1.2 Version. Core Servlets & JSP book: More Servlets & JSP book: www.moreservlets.com Servlet/JSP/Struts/JSF Training: courses.coreservlets.com Slides Marty Hall, http://, books Sun Microsystems Press For live Struts training, please see JSP/servlet/Struts/JSF training courses at http://courses.coreservlets.com/. Taught by the author of Core Servlets and JSP, More Servlets and JSP, and this tutorial. Available at public venues, or customized versions can be held on-site at your organization. Slides Marty Hall, http://, books Sun Microsystems Press

Agenda Understanding Struts Different views of Struts Advantages of Struts Disadvantages of Struts Setting Up Struts Downloading and configuring Struts 1.2 Testing Struts Setting up Struts applications Accessing Struts documentation Adding Struts to an existing Web application 4 Apache Struts: Intro and Setup What is Apache Struts? An MVC Framework? Struts provides a unified framework for deploying servlet and JSP applications that use the MVC architecture. A Collection of Utilities? Struts provides utility classes to handle many of the most common tasks in Web application development A Set of JSP Custom Tag Libraries? Struts provides custom tag libraries for outputting bean properties, generating HTML forms, iterating over various types of data structures, and conditionally outputting HTML. But which is the proper way to view Struts? The answer depends on what you are going to use it for, but the MVC framework is the most common way of looking at Struts. 5 Apache Struts: Intro and Setup

Advantages of Struts (vs. MVC Using RequestDispatcher) Centralized file-based configuration Rather then hard-coding information into Java programs, many Struts values are represented in XML or property files. This loose coupling means that many changes can be made without modifying or recompiling Java code, and that wholesale changes can be made by editing a single file. This approach also lets Java and Web developers focus on their specific tasks (implementing business logic, presenting certain values to clients, etc.) without needing to know about the overall system layout. Form beans In JSP, you can use property="*" with jsp:setproperty to automatically populate a JavaBean component based on incoming request parameters. Apache Struts extends this capability to Java code and adds in several useful utilities, all of which serve to greatly simplify the processing of request parameters. Bean tags Apache Struts provides a set of custom JSP tags (bean:write, in particular) that let you easily output the properties of JavaBeans components. Basically, these are concise and powerful variations of the standard jsp:usebean and jsp:getproperty tags. 6 Apache Struts: Intro and Setup Advantages of Struts (vs. Standard MVC), Continued HTML tags Apache Struts provides a set of custom JSP tags to create HTML forms that are associated with JavaBeans components. This bean/form association serves two useful purposes: It lets you get initial form-field values from Java objects. It lets you redisplay forms with some or all previously entered values intact. Form field validation Apache Struts has builtin capabilities for checking that form values are in the required format. If values are missing or in an improper format, the form can be automatically redisplayed with error messages and with the previously entered values maintained. This validation can be performed on the server (in Java), or both on the server and on the client (in JavaScript). Consistent approach Struts encourages consistent use of MVC throughout your application. 7 Apache Struts: Intro and Setup

Disadvantages of Struts (vs. MVC with RequestDispatcher) Bigger learning curve To use MVC with the standard RequestDispatcher, you need to be comfortable with the standard JSP and servlet APIs. To use MVC with Struts, you have to be comfortable with the standard JSP and servlet APIs and a large and elaborate framework that is almost equal in size to the core system. This drawback is especially significant with smaller projects, near-term deadlines, and less experienced developers; you could spend as much time learning Struts as building your actual system. Worse documentation Compared to the standard servlet and JSP APIs, Struts has fewer online resources, and many first-time users find the online Apache documentation confusing and poorly organized. There are also fewer books on Apache Struts than on standard servlets and JSP. 8 Apache Struts: Intro and Setup Disadvantages of Struts (vs. Standard MVC), Continued Less transparent With Struts applications, there is a lot more going on behind the scenes than with normal Java-based Web applications. As a result, Struts applications are: Harder to understand Harder to benchmark and optimize Rigid approach The flip side of the benefit that Struts encourages a consistent approach to MVC is that Struts makes it difficult (but by no means impossible) to use other approaches. 9 Apache Struts: Intro and Setup

Downloading and Configuring Struts Download the Struts zip file Start at http://jakarta.apache.org/site/binindex.cgi, or follow the link from http://jakarta.apache.org/struts/. Unzip into a directory of your choice For example, unzip into C:\jakarta-struts-1.2.4. I'll refer to this location as struts_install_dir. Update your CLASSPATH Add struts_install_dir/lib/struts.jar to the CLASSPATH used by your compiler or IDE (not your server). Install an XML parser If you have JDK 1.4 or Apache Tomcat, this step is not necessary, since they already come with an XML parser. But, if you use JDK 1.2 or 1.3 with another server, you might need to obtain the XML parsing libraries. Here are two good sources: http://xml.apache.org/ http://java.sun.com/xml/ 10 Apache Struts: Intro and Setup Testing Struts Install struts-blank.war. Install the Web application from struts_install_dir/webapps/struts-blank.war on your server. For example, with Apache Tomcat, copy struts_install_dir/webapps/struts-blank.war to tomcat_install_dir/webapps/. Start or restart the server. Most servers only recognize new Web apps when the server is started. Access http://localhost/struts-blank/. This URL assumes you are running the server on your desktop and are using port 80. In general, access http://hostname:port/struts-blank/. 11 Apache Struts: Intro and Setup

Testing Struts (Results) 12 Apache Struts: Intro and Setup Setting Up Struts Applications Option 1 (Good): Copy/rename the struts-blank directory to your development directory. When you tested your Struts installation, you ran the struts-blank Web app. When you did so, Tomcat and most other servers unpacked the struts-blank.war file into the struts-blank directory. So, copy that directory to whatever location you use for developing custom Web apps, and rename it to whatever app name you choose. For example, if you are using Tomcat and C:\Servlets+JSP is the location you use for development, copy the tomcat_install_dir/webapps/struts-blank directory to C:\Servlets+JSP, rename it to struts-test, resulting in C:\Servlets+JSP\struts-test. Note: the index.jsp in struts-blank should be replaced with your own version. 13 Apache Struts: Intro and Setup

Setting Up Struts Applications Option 2 (Good): Unjar struts-blank.war into your development directory. If your server doesn't automatically unpack WAR files, then even if you ran the struts-blank test described above, you have no regular directory to work with. Besides, some people prefer to unpack the WAR file themselves anyhow. To do so: Copy struts_install_dir/webapps/struts-blank.war to your development directory. Make a new directory (e.g., called struts-test). Unjar struts-blank.war into that directory You can use jar -xvf or a standard zip tool like WinZip or the Windows XP explorer. Whenever you want to test your application, copy struts-test to the server's Web application autodeploy directory (e.g., onto the shortcut to tomcat_install_dir/webapps). Again, remember to replace the index.jsp page in struts-blank 14 Apache Struts: Intro and Setup Setting Up Struts Applications Option 3 (Bad): Rename struts-blank and leave it in the server's deployment directory. It is quite common to work directly in server's deployment directory (e.g., to work directly in tomcat_install_dir/webapps/struts-test). However, this approach scales poorly to real applications, makes it harder to test changes (you have no stable working version), and doesn't support your "real" deployment server anyhow (which is almost certainly not your desktop machine). If you don't have a good deployment system using your IDE or ant scripts, you can easily make a shortcut (Windows) or symbolic link (Unix/Linux) to the server's autodeploy directory, and just copy the Web app onto the shortcut each time. For example: Grab tomcat_install_dir/webapps with your right mouse, drag it into devel_dir, release, and choose "Create Shortcut Here". Create struts-test or other applications as subdirectories within devel_dir, as described above. Deploy by using the right mouse to drag struts-test onto the shortcut from step 1, releasing, and choosing "Copy". 15 Apache Struts: Intro and Setup

Accessing Struts Documentation Read a local copy This is fastest, but the documentation can get a bit out of date. To read a local copy, install the struts-documentation.war Web app. Copy struts_install_dir/webapps/struts-documentation.war to tomcat_install_dir/webapps, restart server, and use the URL http://localhost/struts-documentation/. Read it from the Apache site This option is slower, but guarantees that you get the latest versions of the documentation. Use http://struts.apache.org/learning.html. The documentation includes FAQs, user guides, tutorials, and the API in Javadoc format. 16 Apache Struts: Intro and Setup Adding Struts to an Existing Web Application Copy files into your Web app Copy JAR files from struts-blank/web-inf/lib to your_web_app/web-inf/lib. Copy TLD files from struts-blank/web-inf to your_web_app/web-inf. Copy struts-config.xml from struts-blank/web-inf to your_web_app/web-inf. Copy the application properties file from struts-blank/web- INF/classes/resources to your_web_app/web- INF/classes/resources. If you plan on using the automatic validator, copy validation.xml and validator-rules.xml from struts-blank/web-inf to your_web_app/web-inf. If you plan on using Tiles, copy struts-tiles.xml from strutsblank/web-inf to your_web_app/web-inf. Update web.xml Copy declarations out of struts-blank/web-inf/web.xml into your_web_app/web-inf/web.xml. Most importantly, copy the servlet and servlet-mapping entries that map *.do to org.apache.struts.action.actionservlet. 17 Apache Struts: Intro and Setup

Some Struts Sites: Travel 18 Apache Struts: Intro and Setup Some Struts Sites: Government 19 Apache Struts: Intro and Setup

Some Struts Sites: Commercial 20 Apache Struts: Intro and Setup Struts is Mainstream: Conservatives and Liberals Use It 21 Apache Struts: Intro and Setup

Summary Struts is an MVC framework Also a collection of utilities and custom tag libraries Struts has significant advantages, but adds significant complexity Compare the use of Struts to the use of normal MVC (especially with the JSP 2.0 expression language) Also consider other frameworks, especially JavaServer Faces (JSF). Struts is pretty widely used Test by deploying struts-blank.war Develop by copying the struts-blank directory Don't start from scratch; too many changes needed in your Web app 22 Apache Struts: Intro and Setup Questions? Core Servlets & JSP book: More Servlets & JSP book: www.moreservlets.com Servlet, JSP, Struts, JSF, and Java Training Courses: courses.coreservlets.com Slides Marty Hall, http://, books Sun Microsystems Press