Building Web Applications

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Building Web Applications as PDF for free.

More details

  • Words: 2,011
  • Pages: 103
Building Web Applications

Struts University Series

Building Web Applications Why build web applications? Can we use a conventional design? How are web applications organized? What value does Struts 2 add?

Building Web Applications Why build web applications? Can we use a conventional design? How are web applications organized? What value does Struts 2 add?

Why build web applications? Easier to find, use, and deploy Browsers pre-installed No desktop to maintain Suitable for intranet or Internet

Why build web applications? Downside 

Complex task Web site front-end  Desktop application equivalent 

Are web applications so different? A web application uses a web site as the front-end to a more typical application. In a web application client data input executes business logic on the server. Minnesota State Colleges & Universities http://krypton.mnsu.edu/~spiral/eta/glossary/indxGlossOOxml.html

Are web applications different? Regular Web Site 

HTML, JavaScript, Graphics

Dynamic Web Application 

Common Gateway Interface (CGI) 



Perl, PHP

CGI Equivalents 

Fast CGI, Java, ASP.NET

How do we build web sites? Create dynamic content via code  via server pages  via client-side scripting  and all three in any combination 

Dynamic content via code

Dynamic content via server pages

Plain Old JSP <% User user = ActionContext.getContext() %>
align="right" checked="checked" %> } %> />

...

Server page as rendered

Dynamic content via JavaScript

How much HTML? What is HTML? What tools can we use to write HTML? Can we start with a “Hello World” page? What are the standard elements? What are the most common HTML tags?

How much HTML? Can we dress up “Hello World”? Is there an easier way to style pages? How do we add JavaScript to a page? How do we prepare images for a page? How do we add Flash to a page?

Review In a web application client data input executes ******** ***** on the server.

Review In a web application client data input executes business logic on the server.

Building Web Applications Why web applications? Can we use a conventional design? How are web applications organized? What value does Struts 2 add?

Can we use a conventional design?

Can we use a conventional design?

Can we use a conventional design? “The essential purpose of MVC is to bridge the gap between the human user's mental model and the digital model that exists in the computer.” [Reenskaug 2006|

Can we use a conventional design?

Can we use a conventional design?

Can we use a conventional design?

Can we use a conventional design?

Can we use a conventional design?

Desktop MVC View pulls state  All three components interconnected 

Enterprise MVC Controller pushes state  Controller connects View with Model 

Why bother? For a small application, don't For a large application, MVC ... Helps page share code  Encapsulates navigation  Creates robust pages 

Welcome to the Jungle

Separating code and markup

Review (1) Model (2) View (3) Controller

(a) Renders Model (b) Selects View (c) Retains State

Review (1) Model (2) View (3) Controller

(c) Retains State (a) Renders Model (b) Selects View

Building Web Applications Why web applications? Can we use a conventional design? How are web applications organized? What components does Struts 2 add?

How are web applications organized? Document Root 

*.html, *.jsp 



JSP tags

WEB-INF (Web Application Infrastructure) 

web.xml (Web Application Deployment Descriptor) 



lib 



Servlets, Filters, Listeners, Security Descriptors *.JAR (Java Archive)

classes 

*.class, *.properties, *.tld (tag library descriptor)

How are web applications organized?

Review (1) CGI (2) WEB-INF (3) web.xml (4) JAR (5) TLD

(a) Tag Library Descriptor (b) Java Archive (c) Web Application Infrastructure (d) Computer Gateway Interface (e) Web Application Deployment Descriptor

Review (1) CGI (2) WEB-INF (3) web.xml (4) JAR (5) TLD

(d) Computer Gateway Interface (c) Web Application Infrastructure (e) Web Application Deployment Descriptor (b) Java Archive (a) Tag Library Descriptor

Review To place a resource on the classpath, you can place it under the ******* folder.

Review To place a resource on the classpath, you can place it under the classes folder.

Building Web Applications Why web applications? Can we use a conventional design? How are web applications organized? What value does Struts 2 add?

What value does Struts 2 add? Why add anything? What components does Struts 2 add? How do the Struts internals work? Why use a framework?

What value does Struts 2 add? Why add anything? What comes with Struts? How do the Struts internals work? Why use a framework?

Why add anything? Servlets Server Pages Session Tracking Localization

An embarrassment of riches Servlets 

Heavy-weight, hard to configure, web bound

Server Pages 

Encourages mixing code with markup

Session Tracking 

URL writing is verbose

Localization 

No direct support in scriptlets

Why add anything?

Struts The nearly invisible pieces that hold up buildings, houses, and bridges.

What value does Struts 2 add? Why add anything? What comes with Struts? How do the Struts internals work? Why use a framework?

What comes with Struts? Custom tags Action handler Result handler

What value does Struts 2 add? Custom tags 

Render dynamic content

Action handler Result handler

What value does Struts 2 add? Custom tags 

Render dynamic content

Action handler 

Interacts with other layers

Result handler

What value does Struts 2 add? Custom tags 

Render dynamic content

Action handler 

Interacts with other layers

Result handler 

Dispatches to server page, HTML, PDF, ...

What value does Struts 2 add? Custom tags 

Render dynamic content (View)

Action handler 

Interacts with other layers (Model)

Result handler 

Dispatches to server page (Controller)

Hello.jsp <%@ taglib prefix="s" uri="/tags" %>

<s:text name="message"/>



Hello.properties message = Congratulations! Struts is up and running ... # Add your messages here ...

Hello_es.properties message = ¡Struts está bien! ... # Add your messages here ...

struts.xml <struts> <package name="default" extends="struts-default"> /Hello.jsp

Hello World!

Hello.jsp

Options

  • <s:url id="en" action="Hello"> <s:param name="request_locale">en <s:a href="%{en}">English
  • <s:url id="es" action="Hello"> <s:param name="request_locale">es <s:a href="%{es}">Español


Pick your Poison!

What does Struts 2 add? Why add anything? What value does Struts 2 add? How do the Struts internals work? Why use a framework?

Struts Architecture

Struts Architecture The web browser requests the page The Filter Dispatcher looks at the request and determines the appropriate Action The Interceptors automatically apply common functionality to the request like workflow, validation, and file upload handling The Action method executes, usually storing and/or retrieving information from a database The Result renders the output, be it HTML, images, or PDF, to the browser

Struts Internals Interceptors Value Stack Expression Language

Interceptors: Domain AOP Interceptors allow custom code into the call stack Much of the core functionality of the framework is implemented as Interceptors Custom Interceptors are easy to add

TimerInterceptor TimerInterceptor is the simplest Interceptor Times the execution of the Action public String intercept(ActionInvocation invocation) throws Exception { if (log.isInfoEnabled()) { long startTime = System.currentTimeMillis(); String result = invocation.invoke(); long executionTime = System.currentTimeMillis() - startTime; String namespace = invocation.getProxy().getNamespace(); … }

Preparable public interface Preparable { void prepare() throws Exception; }

protected void intercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); if (action instanceof Preparable) { ... ((Preparable) action).prepare(); ... } } }

Review - Interceptor Interceptors allow custom **** into the request processing pipeline Much of the core ************* of the framework is implemented as Interceptors Custom Interceptors are (hard / easy) to add

Review - Interceptor Interceptors allow custom code into the request processing pipeline Much of the core functionality of the framework is implemented as Interceptors Custom Interceptors are easy to add

Struts Architecture Interceptors Value Stack Expression Language

What is the ValueStack? The ValueStack builds a stack of objects Objects are examined to find property values The ValueStack allows the expression language to find property values across multiple objects

How is the ValueStack used? The Action instance is always pushed onto the ValueStack The Model is pushed on by the ModelDrivenInterceptor The UI tags use it to push values on during their scope and evaluate expressions    

The <s:iterator> tag pushes the current item onto the stack The <s:bean> tag pushes a bean instance on The <s:property> tag evaluates an expression against the ValueStack All tag attribute values are evaluated against the stack when being set onto the tag instances

Review - ValueStack The ValueStack builds a ***** of objects. Objects are examined to find property ******. The ValueStack allows the ********** ******** to find property values across multiple objects.

Review - ValueStack The ValueStack builds a stack of objects Objects are examined to find property values The ValueStack allows the expression language to find property values across multiple objects

Struts Architecture Interceptors Value Stack Expression Language

OGNL Expression Language For expressions, the framework uses OGNL (Object Graph Navigation Language)      

An expression and binding language for getting and setting properties of Java objects Normally the same expression is used for both getting and setting the value of a property Easy to learn, yet powerful Incrementally compiled expressions - fast! Embedded everywhere – views, ValueStack, *.xml Independent Open Source project - http://www.ognl.org

OGNL samples OGNL

Result

user.name

getUser().getName()

user.toString()

getUser().toString()

item.categories[0] @com.example.Test@foo ()

First element of Categories collection Calls the static foo() method on the com.example.Test class

name in {null,”fred”}

True if name is null or “fred”

categories.{name}

Calls getName() on each Category in the collection, returning a new collection (projection)

Review - OGNL OGNL stands for Object Graph ********** Language OGNL is an expression and ******* language for getting and setting properties of Java objects Within the framework, OGNL is ******** everywhere – views, ValueStack, xml configuration files.

Review - OGNL OGNL stands for Object Graph Navigation Language OGNL is an expression and binding language for getting and setting properties of Java objects Within the framework, OGNL is embedded everywhere – views, ValueStack, xml configuration files.

What components does Struts 2 add? Why add anything? What value does Struts 2 add? How do the Struts internals work? Why use a framework?

Why Frameworks? Code reuse Incremental development Long-term maintenance by a team

Why Frameworks? Code reuse Incremental development Long-term maintenance by a team

Why Frameworks? Code reuse Incremental development Long-term maintenance by a team

Why Frameworks? Code reuse Incremental development Long-term maintenance by a team

Review – Why Frameworks? Code re*** In********* development Long-term m********** by a team

********** of Concerns Don't ****** Yourself

Review – Why Frameworks? Code reuse Incremental development Long-term maintenance by a team

Separation of Concerns Don't Repeat Yourself

Review The key framework components are: ****** ****  ****** *******  ****** ******* 

The Struts 2 default configuration file is named ******.xml. To reference the Struts taglib, use the URI “*****”.

Review The key framework components are Custom tags  Action handler  Result handler 

The Struts 2 default configuration file is named struts.xml. To reference the Struts 2 taglib, use the URI “/tags”.

Struts University Series

Building Web Applications Why web applications? Can we use a conventional design? How are web applications organized? What components does Struts 2 add?

Building Web Applications Why web applications? 

Can we use a conventional design? How are web applications organized? What components does Struts 2 add?

Building Web Applications Why web applications? 

Can we use a conventional design?  Absolutely! How are web applications organized? What components does Struts 2 add?

Building Web Applications Why web applications? 

Can we use a conventional design?  Absolutely! How are web applications organized?  WEB-INF, web.xml, /classes What components does Struts 2 add?

Building Web Applications Why web applications? 

Can we use a conventional design?  Absolutely! How are web applications organized?  WEB-INF, web.xml, /classes What components does Struts 2 add?  Tags, Actions, Results

Building Web Applications ....

Struts University Series

Related Documents