Web Applications and Struts 2



Similar documents
Model-View-Controller. and. Struts 2

Web Frameworks and WebWork

Web Applications. Originals of Slides and Source Code for Examples:

Java and Web. WebWork

Course Name: Course in JSP Course Code: P5

Web Applications. For live Java training, please see training courses at

In this chapter, we lay the foundation for all our further discussions. We start

Complete Java Web Development

Server Setup and Configuration

Pentesting Web Frameworks (preview of next year's SEC642 update)

BIRT Application and BIRT Report Deployment Functional Specification

Glassfish, JAVA EE, Servlets, JSP, EJB

Module 13 Implementing Java EE Web Services with JAX-WS

CREATE A CUSTOM THEME WEBSPHERE PORTAL

Web Container Components Servlet JSP Tag Libraries

An introduction to creating JSF applications in Rational Application Developer Version 8.0

How To Understand The Architecture Of Java 2Ee, J2Ee, And J2E (Java) In A Wordpress Blog Post

CrownPeak Java Web Hosting. Version 0.20

Developing Web Applications using JavaServer Pages and Servlets

Volume 1: Core Technologies Marty Hall Larry Brown. An Overview of Servlet & JSP Technology

An Overview of Servlet & JSP Technology

Liferay Enterprise ecommerce. Adding ecommerce functionality to Liferay Reading Time: 10 minutes

Lecture 10 Fundamentals of GAE Development. Cloud Application Development (SE808, School of Software, Sun Yat-Sen University) Yabo (Arber) Xu

Building Web Services with Apache Axis2

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

ServletExec TM 5.0 User Guide

JBoss SOAP Web Services User Guide. Version: M5

CS506 Web Design and Development Solved Online Quiz No. 01

WIRIS quizzes web services Getting started with PHP and Java

Portals, Portlets & Liferay Platform

SSC - Web applications and development Introduction and Java Servlet (II)

Java Application Developer Certificate Program Competencies

MarkLogic Server. Reference Application Architecture Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

Java Servlet and JSP Programming. Structure and Deployment China Jiliang University

Creating Java EE Applications and Servlets with IntelliJ IDEA

SSO Plugin. Integration for Jasper Server. J System Solutions. Version 3.6

Design Approaches of Web Application with Efficient Performance in JAVA

SSC - Web development Model-View-Controller for Java web application development

Customer Bank Account Management System Technical Specification Document

Identity Management in Liferay Overview and Best Practices. Liferay Portal 6.0 EE

Implementing SQI via SOAP Web-Services

CSI 2132 Lab 8. Outline. Web Programming JSP 23/03/2012

Web Application Programmer's Guide

Tutorial: Building a Web Application with Struts

JBoss Portlet Container. User Guide. Release 2.0

Progress OpenEdge REST

Controlling Web Application Behavior

Esigate Module Documentation

It is I, SAML. Ana Mandić Development Five Minutes Ltd

Web-JISIS Reference Manual

A Guide to Understanding Web Application Development Corey Benson, SAS Institute, Inc., Cary, NC Robert Girardin, SAS Institute, Inc.

<Insert Picture Here> Hudson Security Architecture. Winston Prakash. Click to edit Master subtitle style

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

Security Testing of Java web applications Using Static Bytecode Analysis of Deployed Applications

Web Pages. Static Web Pages SHTML

Enterprise Application Development In Java with AJAX and ORM

Hello World Portlet Rendered with JSP for WebSphere Portal Version 4.1

Java Web Programming. Student Workbook

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

DTS Web Developers Guide

Building Web Applications, Servlets, JSP and JDBC

Application Security

Java Servlet 3.0. Rajiv Mordani Spec Lead

Drupal CMS for marketing sites

SSO Plugin. J System Solutions. Upgrading SSO Plugin 3x to 4x - BMC AR System & Mid Tier.

KINETIC SR (Survey and Request)

TIBCO ActiveMatrix BPM Web Application Component Development. Software Release 2.0 November 2012

IT6503 WEB PROGRAMMING. Unit-I

Mastering Tomcat Development

PowerTier Web Development Tools 4

ServletExec TM 6.0 User Guide. for Microsoft Internet Information Server Sun ONE Web Server Sun Java System Web Server and Apache HTTP Server

Keycloak SAML Client Adapter Reference Guide

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

Application Notes for Packaging and Deploying Avaya Communications Process Manager Sample SDK Web Application on a JBoss Application Server Issue 1.

Alfresco. Wiley Publishing, Inc. PROFESSIONAL. PRACTICAL SOLUTIONS FOR ENTERPRISE. John Newton CONTENT MANAGEMENT. Michael Farman Michael G.

Web Application Development

enterprise^ IBM WebSphere Application Server v7.0 Security "publishing Secure your WebSphere applications with Java EE and JAAS security standards

Understanding class paths in Java EE projects with Rational Application Developer Version 8.0

Cache Configuration Reference

SESM Tag Library. Configuring a Tag Library APPENDIX

Master Thesis. Arnold Kemoli. Design and Implementation of a Dynamic Component based Web Application Framework

Servlet 3.0. Alexis Moussine-Pouchkine. mercredi 13 avril 2011

Web Development on the SOEN 6011 Server

Installation Guide for contineo

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

Programma corso di formazione J2EE

Oracle Hyperion Financial Management Custom Pages Development Guide

Server-Side Web Development JSP. Today. Web Servers. Static HTML Directives. Actions Comments Tag Libraries Implicit Objects. Apache.

HPC Portal Development Platform with E-Business and HPC Portlets

TIBCO ActiveMatrix BPM WebApp Component Development

Rapid Application Development. and Application Generation Tools. Walter Knesel

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

Policy Guide Access Manager 3.1 SP5 January 2013

Getting Started with Web Applications

Copyright 2014 Jaspersoft Corporation. All rights reserved. Printed in the U.S.A. Jaspersoft, the Jaspersoft

Building and Using Web Services With JDeveloper 11g

OPENRULES. Release TUTORIAL Cloud Application Development

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Transcription:

Web Applications and Struts 2

Problem area

Problem area Separation of application logic and markup Easier to change and maintain Easier to re use Less error prone Access to functionality to solve routine needs Data transfer between ee client t( (HTTP)and server e (Java) a) Validation Internationalization User interface components (tags)

Web applications Struts 2 sits on top of two important technologies Web framework (Struts 2) Java Servlet specification HTTP

Hypertext Transfer Protocol (HTTP) Series of client server message exchanges Designed for static HTML rather than dynamic Stateless (how to do things like authentication?) Text based (how to map to and from Java types?) Request for a resource Application or web server Web browser Response

Java Servlet specification Provides intuitive object oriented abstraction of HTTP: Servlet (HttpServlet) Small Java program Receive and respond to requests from Web clients Request (HttpRequest) Object representing a client request Access to parameters, a request URL, input stream Response (HttpResponse) Object representing a server response Access to content type, header, writer

Java Servlet specification Session Provides a session between multiple requests Usually corresponds to a user Allows Servlets to bind objects and manipulate information Filter Performs filtering on request sand/or responses Configured in web.xml Useful for authentication, logging

Web application archive Servlets are packaged into web applications as WAR files Zip file with a specific structure Contains: Servlets Java classes Web resources (HTML, CSS, templates, images) Dependent libraries (JARs) / Web resources (HTML, CSS, templates, images) /WEB-INF Private files (not returned by Web server) /WEB-INF/web.xml Deployment descriptor / configuration file /WEB-INF/classes Java classes /WEB-INF/lib Depdendent libraries / JARs

Servlet container Web applications are deployed in Servlet containers Implementation of the Servlet specification Web server able to run and manage the life cycle of servlets Popular open source versions are Tomcat and Jetty http://localhost:8080/webappc/servletb Servlet container WebAppB ServletB ServletA ServletC WebAppA ServletB WebAppC ServletB ServletA ServletC ServletA ServletC

Purpose of Web frameworks Solving application level concerns / routine work! Binding request parameters to Java types Validating data Providing internationalization Rendering presentation layer (HTML etc) Making calls to business layer

Action classes Purposes Encapsulates the work to be done for a request Serve as data carrier in transfer from request to view Determine which result should render the view public class InvertStringAction implements Action private String word; // set-method private String invertedword; d // get-method public String execute() if ( word == null word.trim().length() == 0 ) return INPUT; invertedword = getinvertedword(); // implemented another place return SUCCESS;

Action classes ActionSupport: Abstract convenience class providing: Validation Internationalization Works together with interceptors in the default stack ActionContext: Container holding relevant data for a request: ValueStack auestac Request parameters Session variables Application attributes

ModelDriven Actions Transfers data directly onto model objects Avoids tedious object creation code Provided by interface ModelDriven<T> Exposes method T getmodel()

ModelDriven Actions Class extending ActionSupport and implementing ModelDriven Student instance created getmodel implemented Student object populated with data and ready to use public class SaveStudent extends ActionSupport implements ModelDriven<Student> private Student student = new Student(); public Student getmodel() return student; private StudentService studentservice =//retrieved somehow public String execute() studentservice.savestudent( student ); Don t change object reference! Data will be availabe in view return SUCCESS;

Validation Basic validation accessible from ActionContext The DefaultWorkFlowInterceptor works behind the scenes Separates validation logic from business logic

Validation Class extending ActionSupport Java bean properties public class CalculateAction extends ActionSupport private Integer numerator; private Integer denominator; // set-methods private Double result; // get-method Validate method containing logic public void validate() for checking validity of data Storing errors via methods provided by ActionSupport Validation workflow separated from execution if ( denominator == null ) addfielderror( denominator, Please enter a numerator ); elseif ( denominator == 0 ) addfielderror( denominator, Divison by zero not allowed ); Executemethod containinglogic public String execute() result = // calculate somehow

Validation Input result is used when validation errors exist <action name= calcuate class= no.uio.inf5750.example.action.calculateaction > <result name= success type= velocity >calculate.vm</result> <result name= input type= velocity >calculate.vm</result> </action> Validation error messages printed for appropriate UI tag in view <html> <body> #sform( "action=calculate" ) #stextfield( "label=numerator" "name=numerator" ) #stextfield( "label=denominator" "name=denominator" ) #ssubmit( "value=calculate" ) #end </body> </html>

Internationalization Separation layer between source code and messages Built upon Java resource bundles, which will be found in: Same package and with same name as Action class Classpath after setting struts.custom.i18n.resources config property Messages accessible in Javacode through gettext(..) Locale accessible in Java code through getlocale() Messages accessible in template through key and name Messages accessible in template through key and name properties of UI tags

Internationalization struts.xml configuration <constant name="struts.custom.i18n.resources" value="i18n.i18n" /> i18n.properties in i18n folder on classpath salute=bonjour! Action class using gettext(..) and getlocale() Public class SaluteAction extends ActionSupport public String execute() String salute = gettext( salute ); Locale locale = getlocale(); return SUCCESS; Velocity template using text tag <h3>#stext( "name=salute" )</h3>

UI component tags High level tag API implemented in: JSP Velocity (used in this lecture) Freemarker Data tags Moves oesdata between ee the ValueStack auestac and dthe view Control tags Alters the rendering flow of the view UI tags Provides advanced HTML form controls

Spring integration Useful to apply dependency injection to a Struts 2 application Struts 2 Spring plugin is required (struts2 spring plugin) Spring must be started in web.xml with ContextLoaderListener Approach 1: Define dependencies and actionclasses classes in Spring Class attribute in Struts 2 config will point at Spring bean identifiers Approach 2: Use auto wiring by name Struts 2 will instantiate Actions but let Spring inject beans afterwards Bean identifiers are matched to set methods in Actions

Auto wiring dependencies by name Only the StudentService bean is defined in the configuration <bean id= studentservice class= no.uio.inf5750.model.defaultstudentservice /> Action class provides StudentService property and setmethod Name of set method is matched with Spring bean identifiers public class SaveStudentAction extends ActionSupport private StudentService ts studentservice; ts public voic setstudentservice( StudentService studentservice ) this.studentservice = studentservice; // Student properties and setters public String execute() studentservice.savestudent( savestudent( student );

Summary Struts 2 is built upon the Java Servlet specification which is built upon HTTP Struts t 2 solves application level lroutine work not provided d by the Servlet specifiction Binding request params to Java types Validating data Providing internationalization Rendering presentation layer Making calls to business layer

Resources Brown, Davis, Stanlick: Struts 2 in Action Velocity user guide: http://velocity.apache.org/engine/devel/user guide.html Struts home page: http://struts.apache.org Example code on course homepage