You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2006/01/21 01:21:00 UTC
svn commit: r370938 [37/50] - in /struts: action/trunk/
action/trunk/conf/java/ action/trunk/src/java/org/apache/struts/
action/trunk/src/java/org/apache/struts/action/
action/trunk/src/java/org/apache/struts/chain/
action/trunk/src/java/org/apache/str...
Modified: struts/action/trunk/xdocs/userGuide/preface.xml
URL: http://svn.apache.org/viewcvs/struts/action/trunk/xdocs/userGuide/preface.xml?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/xdocs/userGuide/preface.xml (original)
+++ struts/action/trunk/xdocs/userGuide/preface.xml Fri Jan 20 16:19:02 2006
@@ -18,948 +18,1546 @@
-->
<document>
- <properties>
- <title>Preface: Key Technologies</title>
- </properties>
-
- <body>
-
- <section name="0. Preface: Key Technologies">
-
- <a name="suspects"/>
- <subsection name="0.1 The Usual Suspects">
-
- <p>
- This User Guide is written for active web developers and assumes a working
- knowledge about how Java web applications are built. Before getting started, you should
- understand the basics of several key technologies:
- </p>
-
- <ul>
- <li><a href="#http">HTTP, HTML, and User Agents</a></li>
- <li><a href="#cycle">The HTTP Request/Response Cycle</a></li>
- <li><a href="#java">The Java Language and Application Frameworks</a></li>
- <li><a href="#javabeans">JavaBeans</a></li>
- <li><a href="#resources">Properties Files and ResourceBundles</a></li>
- <li><a href="#servlets">Java Servlets</a></li>
- <li><a href="#jsp">JavaServer Pages and JSP Tag Libraries</a></li>
- <li><a href="#xml">Extensible Markup Language</a></li>
- <li><a href="#jaas">JAAS</a></li>
- <li><a href="#layers">Other Layers</a></li>
- </ul>
-
- <p>
- This chapter briefly defines each of these technologies but does not describe them in detail.
- For your convenience, links to further information are provided if you would like to learn more about a technology.
- </p>
-
- <p id="JavaWebServicesTutorial">If you are familiar with Java, but not these technologies,
- the best overall starting point is
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/index.html"><strong>The Java Web Services Tutorial</strong></a>.
- This document is also available for download in
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/JavaWSTutorial.pdf">PDF</a> format.
- </p>
-
- <p>If you've created web applications for other platforms, you may be able to follow along
- and visit the other references as needed. The core technologies used by the framework are
- also used by most other Java web development products, so the background information will be
- useful in any Java project.
- </p>
-
- <p id="jt">If you are not familiar with the Java language generally,
- then the best starting point is
- <a href="http://java.sun.com/docs/books/tutorial/index.html"><strong>The Java Tutorial</strong></a>.
- This overlaps with the Java Web Services Tutorial in some places, but the two work well together.
- </p>
-
- <p>
- For more about building Java application in general, see the
- <a href="http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part1/toc.jsp">New to
- Java Center</a>.
- </p>
-
- </subsection>
-
- <a name="http"/>
- <subsection name="0.2 HTTP, HTML and User Agents">
-
- <p>The World Wide Web was built over the Hypertext Transfer Protocol
- (<a href="http://www.ietf.org/rfc/rfc2616.txt?number=2616">HTTP</a>) and the Hypertext Markup Language
- (<a href="http://www.w3.org/MarkUp/">HTML</a>). A User Agent, like a web browser, uses HTTP to request
- a HTML document. The browser then formats and displays the document to its user. HTTP is used to
- transport more than HTML, but HTML is the lingua franca of the Web and web applications. </p>
-
- <p>While building web applications, some Java developers will write their own HTML. Others leave that responsibility to the
- page designers.</p>
-
- <p>For more about HTTP, HTML, and User Agents, see:</p>
-
- <ul>
- <li><a href="http://www.w3.org/MarkUp/Guide/"><strong>Getting started with HTML</strong></a> by Dave Raggett</li>
- <li><a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/HTTP.html#63796">
- <strong>HTTP Overview</strong></a> in the Java Web Services Tutorial.</li>
- <li><a href="http://www.rfc-editor.org/rfc/rfc2616.txt"><strong>HTTP/1.1
- </strong></a> Specification</li>
- <li><a href="http://www.rfc-editor.org/rfc/rfc2617.txt"><strong>HTTP
- Basic and Digest Authentication</strong></a> Specification</li>
- <li><a href="http://www.rfc-editor.org/rfc/rfc2109.txt"><strong>State
- Management Mechanism</strong></a> Specification (Cookies)</li>
- </ul>
- </subsection>
-
- <a name="cycle"/>
- <subsection name="0.3 The HTTP Request/Response cycle">
-
- <p>A very important part of HTTP for the web developer is the request/response cycle. To use HTTP
- you have to make a request. A HTTP server, like a web server, is then obliged to respond. When you
- build your web application, you design it to react to a HTTP request by returning a HTTP response.
- Frameworks abstract much of these nuts and bolts, but it is important to understand
- what is happening behind the scenes. </p>
-
- <p>If you are not familiar with the HTTP request/response cycle, we <strong>strongly</strong> recommend the
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/HTTP.html#63796">
- HTTP Overview</a> in the Java Web Services Tutorial.
- </p>
-
- </subsection>
-
- <a name="java"/>
- <subsection name="0.4 The Java Language and Application Frameworks">
-
- <p>The framework is written in the popular and versatile
- <a href="http://java.sun.com/docs/books/jls/first_edition/html/index.html">Java programming language</a>.
- Java is an object-orientated language, and the framework makes good use of many
- object-orientated techniques. In addition, Java natively supports the
- concept of <em>threads</em>, which allows more than one task to be
- performed at the same time. A good understanding of Java, and especially
- object-orientated programming (OOP) and threading, will help
- you get the most out of the framework and this User Guide. </p>
-
- <p>For more about Java and threads, see </p>
-
- <ul>
- <li><a href="http://java.sun.com/docs/books/tutorial/java/index.html"><strong>Learning the Java Language</strong></a> in the Java Tutorial</li>
- <li><a href="http://java.sun.com/docs/books/tutorial/essential/threads/index.html">
- <strong>Threads: Doing Two or More Tasks At Once</strong></a> in the Java Language
- Tutorial</li>
- </ul>
-
- <p>Even if you have worked with Java and OOP before, it can also help to be aware of the
- programming challenges specific to creating and using application frameworks. For more about application
- frameworks, see the classic white papers</p>
-
- <ul>
- <li><a href="http://www.laputan.org/drc/drc.html"><strong>Designing Reusable Classes</strong></a> by Ralph E. Johnson & Brian Foote</li>
- <li><a href="http://www.cs.wustl.edu/~schmidt/CACM-frameworks.html"><strong>Object-Oriented Application Frameworks</strong></a>
- by Mohamed Fayad and Douglas C. Schmidt</li>
- </ul>
-
- <p>These papers can be especially helpful if you are fact-finding or reviewing server-side
- <a href="http://directory.google.com/Top/Computers/Programming/Languages/Java/Server-Side/Libraries_and_Frameworks/">frameworks</a>.
- </p>
-
- </subsection>
-
- <a name="chain"/>
- <subsection name="0.4.1 Chain of Responsibility">
-
- <p>
- A popular technique for organizing the execution of complex
- processing flows is the "Chain of Responsibility" pattern,
- as described (among many other places) in the classic
- <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0201633612/apachesoftwar-20/">
- "Gang of Four" design patterns book.</a>.
- The GoF summarizes the Chain of Responsibility pattern as
- "Avoid coupling the sender of a request to its receiver
- by giving more than one object a chance to handle the request.
- Chain the receiving objects
- and pass the request along the chain until an object handles it."
- </p>
-
- <p>
- The CoR pattern helps us keep software components loosely coupled.
- A component can call a Chain of Responsbility,
- without knowing what objects are on the chain or how they are
- implemented.
- Most importantly, we can adjust the Chain without changing
- how callers invoke the Chain.
- As of version 1.3,
- the default Request Processor,
- which acts as the framework's "kernal",
- is a Chain of Responsiblity.
- </p>
-
- <p>
- To implement its Chain, the Request Processor uses the
- <a href="http://jakarta.apache.org/commons/chain/">
- Chain of Responsibility </a>component in the Jakarta Commons
- which provides a standard implementation of the CoR pattern,
- along with various implementations of the Context and
- Command objects used by the Chain to service a request.
- </p>
-
- <p>
- For more about Chain of Responsiblity, see
- </p>
-
- <ul>
- <li>
- <a href="http://jakarta.apache.org/commons/chain/">
- Jakarta Commons Chain of Responsibility </a>
- </li>
- <li>
- <a href="http://www.onjava.com/lpt/a/5671">
- A look at Commons Chain</a>
- </li>
- <li>
- <a href="http://www.infonoia.com/en/content.jsp?d=inf.05.06&pr=1">
- Better Code with Struts 1.3
- </a>
- </li>
- </ul>
-
- </subsection>
-
- <a name="javabeans"/>
- <subsection name="0.5 JavaBeans">
-
- <p>Like many Java applications, most of the framework objects are designed as
- <a href="http://java.sun.com/products/javabeans/">JavaBeans</a>. Following the JavaBean design patterns makes
- the framework's classes easier to use -- both by Java developers and by Java development tools. </p>
-
- <p>Although JavaBeans were first created for visual elements, these object design patterns have been found to
- be useful as the basis for any reusable component, like those used by the framework.</p>
-
- <p>For more about JavaBeans, see:</p>
-
- <ul>
- <li><a href="http://java.sun.com/products/javabeans/docs/"><strong>The
- JavaBeans Component Architecture Documentation</strong></a> page at
- <code>java.sun.com</code>, including a link to download the
- <a href="http://java.sun.com/products/javabeans/docs/spec.html">
- JavaBeans 1.01 Specification</a></li>
- <li><a href="http://java.sun.com/docs/books/tutorial/javabeans/index.html">
- <strong>The JavaBeans Trail</strong></a> in the Java Tutorial</li>
- <li><a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSPBeans.html">
- <strong>JavaBeans Components in JSP Pages</strong></a> in the Java Web Services Tutorial
- </li>
- </ul>
-
- </subsection>
-
- <a name="reflection"/>
- <subsection name="0.5.1 Reflection and Introspection">
-
- <p>
- Reflection is the process of determining which member fields and methods are available on an object.
- Introspection is a specialized form of reflection used by the JavaBean API.
- Using Introspection, we can determine which methods of a JavaBean are intended to be accessed by other objects.
- (The getters and the setters, for example.)
- </p>
-
- <p>
- The framework uses Introspection to convert HTTP parameters into JavaBean properties and to populate HTML fields from JavaBean properties.
- This technique makes it easy to "roundtrip" properties between HTML forms and JavaBeans.
- </p>
-
- <p>
- For more about Reflection and Introspection, see
- </p>
-
- <ul>
- <li>
- <a href="http://java.sun.com/docs/books/tutorial/reflect/">The Reflection Trail</a>
- </li>
- <li>
- <a href="http://java.sun.com/products/javabeans/docs/spec.html">Chapter 8 of the JavaBeans API Specification</a>
- </li>
- </ul>
-
- </subsection>
-
- <a name="maps"/>
- <subsection name="0.5.2 Maps">
-
- <p>
- JavaBeans store data as properties and may act on that data through other methods.
- JavaBeans are flexible and powerful objects but are not the only object that programmers use to store data.
- Another popular object is the Map [<code>java.util.Map</code>].
- A Map is a simple collection of name and value pairs.
- Maps are often used "behind the scenes" as a flexible way to store dynamic data.
- </p>
-
- </subsection>
-
- <a name="dynabeans"/>
- <subsection name="0.5.3 DynaBeans">
-
- <p>
- DynaBeans combine the extensibility of JavaBeans with the flexibility of a Map.
- Defining even the simplest JavaBean requires defining a new class and coding a field and two methods for each property.
- The properties of a DynaBean can be configured via an XML descriptor.
- The virtual properties of a DynaBean can't be called by standard Java methods,
- but work well with components that rely on reflection and introspection.
- </p>
-
- <p>
- In your application, you can use DynaBeans to describe your HTML forms.
- This strategy can avoid creating a formal JavaBean subclass to store a few simple properties.
- </p>
-
- <p>
- For more about DynaBeans, see
- </p>
-
- <ul>
- <li>
- The Commons BeanUtils
- <a href="http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/package-summary.html#package_description">
- Package Description</a> and <a href="http://jakarta.apache.org/commons/beanutils/api/index.html">Javadocs</a>.
- </li>
- <li>
- <a href="https://formdef.dev.java.net/">Struts FormDef</a>
- </li>
- </ul>
-
- </subsection>
-
- <a name="resources"/>
- <subsection name="0.6 Properties Files and ResourceBundles">
-
- <p>Java applications, including web applications, are often configured using
- <a href="http://java.sun.com/j2se/1.4.1/docs/api/java/util/Properties.html">Properties</a>
- files. Properties files are the basis for the
- <a href="http://java.sun.com/j2se/1.4.1/docs/api/java/util/ResourceBundle.html">ResourceBundles</a> that the framework uses to provide message resources
- to an application. </p>
-
- <p>For more about Properties files, see: </p>
-
- <ul>
- <li><a href="http://java.sun.com/docs/books/tutorial/essential/attributes/properties.html">
- <strong>Using Properties to Manage Program Attributes</strong></a> in The Java Tutorial</li>
- </ul>
-
- <p>Java ResourceBundles use one or more Properties files to provide internationalized messages
- to users based their
- <a href="http://java.sun.com/j2se/1.4.1/docs/api/java/util/Locale.html">Locale</a>.
- Support for localizing an application was built into the framework from the ground-up.</p>
-
- <p>For more about localization and ResourceBundles, see </p>
-
- <ul>
- <li><a href="http://java.sun.com/docs/books/tutorial/i18n/resbundle/concept.html"><strong>About the ResourceBundle Class</strong></a>
- in the Java Tutorial</li>
- </ul>
-
- </subsection>
-
- <a name="servlets"/>
- <subsection name="0.7 Java Servlets">
- <p>
- Since Java is an object-orientated language, the
- <a href="http://www.novocode.com/doc/servlet-essentials/">Java Servlet</a>
- platform strives to cast HTTP into an object-orientated form.
- This strategy makes it easier for Java developers to concentrate on what they need their application to do --
- rather than the mechanics of HTTP.
- </p>
-
- <p>
- HTTP provides a standard mechanism for extending servers called the Common Gateway Interface, or CGI.
- The server can pass a request to a CGI-aware program, and the program will pass back a response.
- Likewise, a Java-aware server can pass a request to a servlet container.
- The container can fulfill the request or it can pass the request back to the HTTP server.
- The container decides whether it can handle the request by checking its list of servlets.
- If there is a servlet registered for the request, the container passes the request to the servlet.
- </p>
-
- <p>
- When a request comes in, the container checks to see if there is a servlet registered for that request.
- If there is a match,
- the request is given to the servlet.
- If not, the request is returned to the HTTP server.
- </p>
-
- <p>
- It's the container's job to manages the servlet lifecycle.
- The container creates the servlets, invokes the servlets, and ultimately disposes the servlets.
- </p>
-
- <p>
- A servlet is generally a subclass of <code>javax.servlet.http.HttpServlet</code>.
- A servlet must implement four methods, which are invoked by the container as needed:
- </p>
-
- <ul>
- <li><strong>public void init(ServletConfig config)</strong> - Called by the
- servlet container when the servlet instance is first created, and
- before any request is processed.</li>
- <li><strong>public void doGet(HttpServletRequest request,
- HttpServletResponse response)</strong> - Called to process a
- specific request received using the HTTP <code>GET</code> protocol,
- which generates a corresponding dynamic response.</li>
- <li><strong>public void doPost(HttpServletRequest request,
- HttpServletResponse response)</strong> - Called to process a
- specific request received using the HTTP <code>POST</code> protocol,
- which generates a corresponding dynamic response.</li>
- <li><strong>public void destroy()</strong> - Called by the servlet
- container when it takes this servlet instance out of service,
- such as when a web application is being undeployed or when the
- entire container is being shut down.</li>
- </ul>
-
- <p>
- The framework provides a ready-to-use servlet for your application [<code>org.apache.struts.action.ActionServlet</code>].
- As a Struts developer, you can then just write objects that the Struts ActionServlet calls when needed.
- But it is still helpful to understand the basics of what servlets are,
- and the role they play in a Java web application.
- </p>
-
- <p>
- For more about Java Servlets, see:
- </p>
-
- <ul>
- <li><a href="http://java.sun.com/products/servlet/"><strong>The
- Java Servlet Technology</strong></a> page at
- <code>java.sun.com</code></li>
- <li><a href="http://java.sun.com/products/servlet/download.html"><strong>The
- Servlet 2.2 and 2.3 Specifications</strong></a> download page at
- <code>java.sun.com</code></li>
- <li><a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets.html">
- <strong>Java Servlet Technology</strong></a> in the Java Web Services Tutorial.</li>
- <li><a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/WebApp.html">
- <strong>Web Applications</strong></a> in the Java Web Services Tutorial.</li>
- </ul>
-
- </subsection>
-
- <a name="threads"/>
- <subsection name="0.7.1 Servlets and threads">
-
- <p>
- To boost performance, the container can multi-thread servlets.
- Only one instance of a particular servlet is created,
- and each request for that servlet passes through the same object.
- This strategy helps the container make the best use of available resources.
- The tradeoff is that the servlet's <code>doGet()</code> and <code>doPost()</code> methods must be programmed in a <em>thread-safe</em> manner.
- </p>
-
- <p>
- For more about servlets and thread-safety, see:
- </p>
-
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets5.html#64386">Controlling Concurrent Access to Shared Resources</a> in Java Web Services Tutorial.
- </li>
- </ul>
-
- </subsection>
-
- <a name="context"/>
- <subsection name="0.7.2 Servlet Context">
-
- <p>The <em>ServletContext</em> interface [<code>javax.servlet.ServletContext</code>] defines a servlet's view of
- the web application within which the servlet is running. It is
- accessible in a servlet via the <code>getServletConfig()</code> method,
- and in a JSP page as the <code>application</code> implicit variable.
- Servlet contexts provide several APIs that are very useful in building
- Struts based web applications:</p>
- <ul>
- <li><em>Access To Web Application Resources</em> - A servlet can
- access static resource files within the web application using the
- <code>getResource()</code> and <code>getResourceAsStream()</code>
- methods.</li>
- <li><em>Servlet Context Attributes</em> - The context makes available
- a storage place for Java objects, identified by string-valued keys.
- These attributes are global to the entire web application, and may
- be accessed by a servlet using the <code>getAttribute()</code>,
- <code>getAttributeNames()</code>, <code>removeAttribute()</code>, and
- <code>setAttribute()</code> methods. From a JSP page, servlet
- context attributes are also known as "application scope beans".
- </li>
- </ul>
-
- <p>
- For more about the servlet context, see:
- </p>
-
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets10.html#64724">Accessing the Web Context</a> in Java Web Services Tutorial.
- </li>
- </ul>
-
- </subsection>
-
- <a name="request"/>
- <subsection name="0.7.3 Servlet Request">
-
- <p>Each request processed by a servlet is represented by a Java
- interface, normally a <code>HttpServletRequest</code>
- [<code>javax.servlet.http.HttpServletRequest</code>].
- The request interface provides an object-oriented mechanism to access
- all of the information that was included in the underlying HTTP request,
- including:</p>
- <ul>
- <li><em>Cookies</em> - The set of cookies included with this request
- are available via the <code>getCookies()</code> method.</li>
- <li><em>Headers</em> - HTTP headers that were included with
- the request are accessible by name. You can enumerate the names
- of all included headers.</li>
- <li><em>Parameters</em> - Request parameters, including those from
- the query string portion of the URL and from the embedded content
- of the request (POST only) are available by name.</li>
- <li><em>Request Characteristics</em> - Many other characteristics
- of the incoming HTTP request, such as the method used (normally
- GET or POST) the protocol scheme used ("http" or "https"), and
- similar values.</li>
- <li><em>Request URI Information</em> - The original request URI
- being processed is available via <code>getRequestURI()</code>.
- In addition, the constituent parts into which the servlet container
- parses the request URI (contextPath, servletPath, and pathInfo) are
- available separately.</li>
- <li><em>User Information</em> - If you are using
- <a href="#security">Container Managed Security</a>, you can ask for
- the username of the authenticated user, retrieve a
- <code>Principal</code> object representing the current user, and
- whether the current user is authorized for a specified role.</li>
- </ul>
-
- <p>In addition, servlet requests support <em>request attributes</em>
- (from JSP, these are "request scope beans"), analogous to the servlet
- context attributes described above. Request attributes are often used
- to communicate state information from a business logic class that
- generates it to a view component (such as a JSP page) that will use
- the information to produce the corresponding response.</p>
-
- <p>The servlet container guarantees that a particular request will
- be processed by a servlet on a single thread. Therefore, you do not
- generally have to worry about the thread safety of your access to
- request properties and attributes.</p>
-
- <p>
- For more about the servlet request, see:
- </p>
-
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets7.html#64433">Getting Information from Requests</a> in Java Web Services Tutorial.
- </li>
- </ul>
-
- </subsection>
-
- <a name="response"/>
- <subsection name="0.7.4 Servlet Response">
-
- <p>The primary purpose of a servlet is to process an incoming
- <a href="#request">Servlet Request</a> [<code>javax.servlet.http.HttpServletRequest</code>]
- and convert it into a
- corresponding response. This is performed by calling appropriate
- methods on the servlet response [<code>javax.servlet.http.HttpServletResponse</code>]
- interface. Available methods let you:</p>
- <ul>
- <li><em>Set Headers</em> - You can set HTTP headers that will be
- included in the response. The most important header is the
- <code>Content-Type</code> header, which tells your client what
- kind of information is included in the body of this response.
- This is typically set to <code>text/html</code> for an HTML page,
- or <code>text/xml</code> for an XML document.</li>
- <li><em>Set Cookies</em> - You can add cookies to the current
- response.</li>
- <li><em>Send Error Responses</em> - You can send an HTTP error status
- (instead of a usual page of content) using
- <code>sendError()</code>.</li>
- <li><em>Redirect To Another Resource</em> - You can use the
- <code>sendRedirect()</code> method to redirect the client to
- some other URL that you specify.</li>
- </ul>
-
- <p>An important principle in using the servlet response APIs is that
- any methods you call to manipulate headers or cookies
- <strong>MUST</strong> be performed before the first buffer-full of
- content has been flushed to the client. The reason for this restriction
- is that such information is transmitted at the beginning of the HTTP
- response, so trying things like adding a header after the headers have
- already been sent will not be effective.</p>
-
- <p>
- When you are using presentation pages in a Model 2 application,
- you will not generally use the servlet response APIs directly.
- In the case of JavaServerPages, the JSP page compiler
- in your servlet container will convert your page into a servlet.
- The JSP servlet renders the response, interspersing dynamic
- information where you have interposed JSP custom tags.
- </p>
-
- <p>
- Other presentation systems, like Velocity Tools for Struts,
- may delegate rendering the response to a specialized servlet,
- but the same pattern holds true.
- You create a template,
- and the dynamic response is generated automatically from the template.
- </p>
-
- <p>
- For more about the servlet response, see:
- </p>
-
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets7.html#64531">Constructing Responses</a> in Java Web Services Tutorial.
- </li>
- </ul>
-
- </subsection>
-
- <a name="filter"/>
- <subsection name="0.7.5 Filtering">
-
- <p>If you are using a servlet container based on version
- <strong>2.3</strong> or later of the Servlet Specification (such as
- Tomcat 4.x), you can take advantage of the new Filter APIs
- [<code>javax.servlet.Filter</code>] that
- let you compose a set of components that will process a request or
- response. Filters are aggregated into a chain in which each filter
- has a chance to process the request and response before and after
- it is processed by subsequent filters (and the servlet that is ultimately
- called).</p>
-
- <p>The Struts 1.0, 1.1, and 1.2 versions require only version 2.2 or later
- of the Servlet Specification to be implemented by your servlet container,
- so those versions do not use Filters. Beginning with the
- 1.3 version, a container that supports version 2.3 or later of the Servlet
- Specification is required, and it is possible that the framework might use
- Filters in the future.</p>
-
- <p>
- For more about filters, see:
- </p>
-
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets8.html#64572">Filtering Requests and Responses</a>
- </li>
- </ul>
-
- </subsection>
-
- <a name="session"/>
- <subsection name="0.7.6 Sessions">
-
- <p>One of the key characteristics of HTTP is that it is
- <em>stateless</em>. In other words, there is nothing built in to
- HTTP that identifies a subsequent request from the same user as being
- related to a previous request from that user. This makes building an
- application that wants to engage in a conversation with the user over
- several requests to be somewhat difficult.</p>
-
- <p>To alleviate this difficulty, the servlet API provides a programmatic
- concept called a <em>session</em>, represented as an object that
- implements the <code>javax.servlet.http.HttpSession</code> interface.
- The servlet container will use one of two techniques (cookies or
- URL rewriting) to ensure that the next request from the same user will
- include the <em>session id</em> for this session, so that state
- information saved in the session can be associated with multiple
- requests. This state information is stored in <em>session
- attributes</em> (in JSP, they are known as "session scope beans").</p>
-
- <p>To avoid occupying resources forever when a user fails to complete
- an interaction, sessions have a configurable <em>timeout interval</em>.
- If the time gap between two requests exceeds this interval, the session
- will be timed out, and all session attributes removed. You define a
- default session timeout in your web application deployment descriptor,
- and you can dynamically change it for a particular session by calling
- the <code>setMaxInactiveInterval()</code> method.</p>
-
- <p>Unlike requests, you need to be concerned about thread safety on
- your session attributes (the methods these beans provide, not the
- <code>getAttribute()</code> and <code>setAttribute()</code> methods
- of the session itself). It is surprisingly easy for there to be
- multiple simultaneous requests from the same user, which will therefore
- access the same session.</p>
-
- <p>Another important consideration is that session attributes occupy
- memory in your server <em>in between</em> requests. This can have
- an impact on the number of simultaneous users that your application can
- support. If your application requirements include very large numbers of
- simultaneous users, you will likely want to minimize your use of
- session attributes, in an effort to control the overall amount of memory
- required to support your application.</p>
-
- <p>
- For more about sessions, see:
- </p>
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets11.html#64744">Maintaining Client State</a> in Java Web Services Tutorial
- </li>
- <li>
- <a href="http://java.sun.com/products/servlet/2.1/api/javax.servlet.http.HttpSession.html"><code>javax.servlet.http.HttpSession</code></a>
- </li>
- </ul>
-
- </subsection>
-
- <a name="dispatch"/>
- <subsection name="0.7.7 Dispatching Requests">
-
- <p>
- The Java Servlet specification extends the HTTP request/response cycle by allowing the request to be dispatched,
- or forwarded, between resources.
- The framework uses this feature to pass a request through specialized components,
- each handling one aspect of the response.
- In the normal course, a request may pass through a controller object, a model object,
- and finally to a view object as part of a single request/response cycle.
- </p>
-
- </subsection>
-
- <a name="webapp"/>
- <subsection name="0.7.8 Web Applications">
-
- <p>
- Just as a HTTP server can be used to host several distinct web sites,
- a servlet container can be used to host more than one web application.
- The Java servlet platform provides a well-defined mechanism for organizing and deploying web applications.
- Each application runs in its own namespace so that they can be developed and deployed separately.
- A web application can be assembled into a Web Application Archive, or WAR file.
- The single WAR can be uploaded to the server and automatically deployed.
- </p>
-
- <p>
- For more about web applications, see:
- </p>
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/WebApp.html#76431">Web Applications</a> in Java Web Services Tutorial
- </li>
- </ul>
-
- </subsection>
-
- <a name="events"/>
- <subsection name="0.7.9 Web application deployment descriptor (web.xml)">
-
- <p>
- Most aspects of an application's lifecycle are configured through an XML document called the Web application deployment descriptor.
- The schema of the descriptor, or web.xml, is given by the Java servlet specification.
- </p>
-
- <p>
- For more about the web.xml and application lifecycle events, see:
- </p>
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/WebApp2.html#64550">Web Application Life Cycle</a> in Java Web Services Tutorial
- </li>
- </ul>
-
- </subsection>
-
- <a name="security"/>
- <subsection name="0.7.10 Security" href="">
-
- <p>
- One detail that can be configured in the Web application deployment descriptor is container-managed security.
- Declarative security can be used to protect requests for URIs that match given patterns.
- Pragmatic security can be used to fine-tune security make authorization decisions based on the time of day,
- the parameters of a call, or the internal state of a Web component.
- It can also be used to restrict authentication based on information in a database.
- </p>
-
- <p>For more information about container-managed security, see:</p>
- <ul>
- <li><a href="http://java.sun.com/webservices/docs/1.2/tutorial/doc/index.html">
- Web Application Security (Chapter 24)</a> in the Java Web Services Tutorial
- </li>
- </ul>
-
- </subsection>
-
- <a name="jsp"/>
- <subsection name="0.8 JavaServer Pages, JSP Tag Libraries, and JavaServer Faces" href="">
- <p><a href="http://java.sun.com/products/jsp/product.html">JavaServer Pages</a> (JSPs) are
- "inside-out servlets" that make it easier to create and maintain dynamic web pages. Instead
- of putting what you want to write to the HTTP response inside of a Java <code>print</code>
- statement, everything in a JavaServer Page is written to the response, <strong>except</strong> what is
- placed within special Java statements.</p>
-
- <p>With <strong>JavaServer Pages</strong> you can start by writing the page in standard HTML and then add the
- dynamic features using statements in the Java language or by using
- <a href="http://java.sun.com/products/jsp/taglibraries.html">JSP tags</a>.
- The Struts Classic distribution includes several JSP tags that make it easy to access the framework's
- features from a JavaServer Page.</p>
-
- <p>For more about JavaServer Pages and Custom JSP Tag Libraries see </p>
-
- <ul>
- <li><a href="http://java.sun.com/products/jsp/"><strong>The
- JavaServer Pages Technology</strong></a> page at
- <code>java.sun.com</code></li>
- <li><a href="http://java.sun.com/products/jsp/download.html"><strong>The
- JSP 1.1 and 1.2 Specifications</strong></a> download page at
- <code>java.sun.com</code></li>
- <li><a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSPIntro.html"><strong>JavaServer Pages Technology</strong></a> in the Java Web Services Tutorial</li>
- <li><a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSPTags.html"><strong>Custom Tags in JSP Pages</strong></a> in the Java Web Services Tutorial</li>
- </ul>
-
- <p>Many times, JSP tags work hand-in-hand with JavaBeans. The application sends a JavaBean to
- the JSP, and the JSP tag uses the bean to customize the page for the instant user. For more, see
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSPBeans.html">JavaBeans Components in JSP Pages</a>
- in the Java Web Services Tutorial.</p>
-
- <p>The framework also works well with the
- <a href="http://java.sun.com/products/jsp/jstl"><strong>JavaServer Pages Standard Tag Library</strong></a>
- (JSTL) and taglibs from other sources, like
- <a href="http://jsptags.com/">JSP Tags</a>,
- <a href="http://jakarta.apache.org/taglibs/index.html">Jakarta Taglibs</a>,
- <a href="http://struts.application-servers.com">Struts Layout</a>, and
- <a href="http://http://displaytag.sourceforge.net/">Display Tags</a>.
- </p>
-
- <p>
- One of the subprojects available for Struts Classic is <a href="http://struts.apache.org/struts-el/index.html">Struts-EL</a>.
- This taglib is specifically designed to work well with JSTL.
- In particular, it uses the same "expression language" engine for evaluating tag attribute values as JSTL.
- This is in contrast to the original Struts tag library, which can only use "rtexprvalue"s (runtime scriptlet
- expressions) for dynamic attribute values.
- </p>
-
- <p>There are also toolkits available that make the framework easy to use with
- <a href="http://stxx.sourceforge.net/">XSLT</a> and
- <a href="http://jakarta.apache.org/velocity/tools/index.html">Velocity Templates</a>.
- </p>
-
- <p>
- The newest star on the Java horizon is <a href="http://java.sun.com/j2ee/javaserverfaces/">JavaServer Faces technology</a>.
- JSF simplifies building user interfaces for JavaServer applications, both for the web and for the desktop.
- To keep pace, Apache Struts is offering a new framework to go with this new technology, called
- <a href="http://struts.apache.org/struts-shale/index.html">Struts Shale</a>.
- For teams looking for a smoother transition to JSF, we offer Struts-Faces taglib,
- which lets you use JSF components with your existing Actions.
- </p>
- <p>
- For an open source implementation of JSF, visit our sibling project
- .
- </p>
-
- <p>For more about JSTL and JavaServer Faces see </p>
-
- <ul>
- <li>
- <a href="http://today.java.net/pub/a/today/2003/10/07/jstl1.html">Practical JSTL, Part 1</a>
- by Sue Spielman
- </li>
- <li>
- <a href="http://www.jsfcentral.com"><strong>JSF Central</strong></a> - JavaServer Faces resources.
- </li>
- <li>
- <a href="http://www.jamesholmes.com/JavaServerFaces/"><strong>JavaServer Faces Resources</strong></a>
- - James Holmes dot Com.
- </li>
- <li> <a href="http://myfaces.apache.org">Apache MyFaces</a> - An open source implementation of
- the JSF specification.
- </li>
- </ul>
-
- </subsection>
-
- <a name="xml"/>
- <subsection name="0.9 Extensible Markup Language (XML)" href="">
-
- <p>The features provided by the framework rely on a number of objects that are
- usually deployed using a configuration file written in
- <a href="http://www.w3.org/XML/">Extensible Markup Language</a>. XML is also used to
- configure Java web applications; so, this is yet another familiar approach.
- </p>
-
- <p>For more about XML configuration files and Java web applications, see</p>
-
- <ul>
- <li>
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/WebApp4.html#64678">Configuring Web
- Applications</a> in the Java Web Services Tutorial</li>
- </ul>
-
- <p>
- For more about how XML is used with Java applications generally, see
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/JAXPIntro.html">Java API for XML Processing</a>
- in the Java Web Services Tutorial.
- While the framework makes good use of this API internally, it is not something most Struts developers would use
- when writing their own applications.
- </p>
-
- </subsection>
- <a name="descriptors"/>
- <subsection name="0.9.1 Descriptors" href="descriptors">
-
- <p>
- When Java applications use XML configuration files,
- the elements are most often used as <em>descriptors</em>.
- The application does not use the XML elements directly.
- The elements are used to create and configure (or deploy) Java objects.
- </p>
-
- <p>
- The Java Servlet platform uses an XML configuration file to deploy servlets (among other things).
- Likewise, The framework uses an XML configuration file to deploy objects.
- </p>
-
- </subsection>
-
- <a name="jaas"/>
- <subsection name="0.10 JAAS" href="">
-
- <p>
- While the framework can work with any approach to user authentication and authorization, Struts 1.1 and later offers
- direct support for the standard Java Authentication and Authorization Service (JAAS).
- You can now specify security roles on an action-by-action basis.
- </p>
-
- <p>For more about JAAS, see the Sun Developer Network
- <a href="http://java.sun.com/products/jaas">product page</a>
- and the <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/WebAppSecurity.html">
- Web Application Security</a> chapter of the
- <a href="http://java.sun.com/webservices/docs/1.0/tutorial/index.html">Java Web Services Tutorial</a>.</p>
-
- <p>
- A popular extension for handling security in a Java web application, including a framework application,
- is <a href="http://securityfilter.sourceforge.net/">SecurityFilter</a>.
- </p>
- </subsection>
-
- <a name="layers"/>
- <subsection name="0.11 Other layers">
-
- <p>
- The framework provides the control layer for a web application.
- Developers can use this layer with other standard technologies
- to provide the business, data access, and presentation layers.
- </p>
-
- <p>
- For more about creating business and data access layers,
- see the "<a href="building_model.html">Building Model Components</a>"
- section.
- </p>
-
- <p>
- For more about creating the presentation layer,
- see the "<a href="building_model.html">Building View Components</a>"
- section.
- </p>
-
- </subsection>
-
-</section>
-
-<section>
- <p class="right">
- Next: <a href="introduction.html">Introduction</a>
- </p>
-</section>
+ <properties>
+ <title>Preface: Key Technologies</title>
+ </properties>
+
+ <body>
+
+ <section name="0. Preface: Key Technologies">
+
+ <a name="suspects"/>
+ <subsection name="0.1 The Usual Suspects">
+
+ <p>
+ This User Guide is written for active web developers and
+ assumes a working
+ knowledge about how Java web applications are built.
+ Before getting started, you should
+ understand the basics of several key technologies:
+ </p>
+
+ <ul>
+ <li>
+ <a href="#http">HTTP, HTML, and User Agents</a>
+ </li>
+ <li>
+ <a href="#cycle">The HTTP Request/Response Cycle</a>
+ </li>
+ <li>
+ <a href="#java">The Java Language and Application
+ Frameworks</a>
+ </li>
+ <li>
+ <a href="#javabeans">JavaBeans</a>
+ </li>
+ <li>
+ <a href="#resources">Properties Files and
+ ResourceBundles</a>
+ </li>
+ <li>
+ <a href="#servlets">Java Servlets</a>
+ </li>
+ <li>
+ <a href="#jsp">JavaServer Pages and JSP Tag
+ Libraries</a>
+ </li>
+ <li>
+ <a href="#xml">Extensible Markup Language</a>
+ </li>
+ <li>
+ <a href="#jaas">JAAS</a>
+ </li>
+ <li>
+ <a href="#layers">Other Layers</a>
+ </li>
+ </ul>
+
+ <p>
+ This chapter briefly defines each of these technologies
+ but does not describe them in detail.
+ For your convenience, links to further information are
+ provided if you would like to learn more about a
+ technology.
+ </p>
+
+ <p id="JavaWebServicesTutorial">If you are familiar with Java,
+ but not these technologies,
+ the best overall starting point is
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/index.html">
+ <strong>The Java Web Services Tutorial</strong>
+ </a>
+ .
+ This document is also available for download in
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/JavaWSTutorial.pdf">
+ PDF</a>
+ format.
+ </p>
+
+ <p>If you've created web applications for other platforms, you
+ may be able to follow along
+ and visit the other references as needed. The core
+ technologies used by the framework are
+ also used by most other Java web development products, so
+ the background information will be
+ useful in any Java project.
+ </p>
+
+ <p id="jt">If you are not familiar with the Java language
+ generally,
+ then the best starting point is
+ <a href="http://java.sun.com/docs/books/tutorial/index.html">
+ <strong>The Java Tutorial</strong>
+ </a>
+ .
+ This overlaps with the Java Web Services Tutorial in some
+ places, but the two work well together.
+ </p>
+
+ <p>
+ For more about building Java application in general, see
+ the
+ <a href="http://developer.java.sun.com/developer/onlineTraining/new2java/divelog/part1/toc.jsp">
+ New to
+ Java Center</a>
+ .
+ </p>
+
+ </subsection>
+
+ <a name="http"/>
+ <subsection name="0.2 HTTP, HTML and User Agents">
+
+ <p>The World Wide Web was built over the Hypertext Transfer
+ Protocol
+ (
+ <a href="http://www.ietf.org/rfc/rfc2616.txt?number=2616">
+ HTTP</a>
+ ) and the Hypertext Markup Language
+ (
+ <a href="http://www.w3.org/MarkUp/">HTML</a>
+ ). A User Agent, like a web browser, uses HTTP to request
+ a HTML document. The browser then formats and displays the
+ document to its user. HTTP is used to
+ transport more than HTML, but HTML is the lingua franca of
+ the Web and web applications.
+ </p>
+
+ <p>While building web applications, some Java developers will
+ write their own HTML. Others leave that responsibility to
+ the
+ page designers.</p>
+
+ <p>For more about HTTP, HTML, and User Agents, see:</p>
+
+ <ul>
+ <li>
+ <a href="http://www.w3.org/MarkUp/Guide/">
+ <strong>Getting started with HTML</strong>
+ </a>
+ by Dave Raggett
+ </li>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/HTTP.html#63796">
+ <strong>HTTP Overview</strong>
+ </a>
+ in the Java Web Services Tutorial.
+ </li>
+ <li>
+ <a href="http://www.rfc-editor.org/rfc/rfc2616.txt">
+ <strong>HTTP/1.1
+ </strong>
+ </a>
+ Specification
+ </li>
+ <li>
+ <a href="http://www.rfc-editor.org/rfc/rfc2617.txt">
+ <strong>HTTP
+ Basic and Digest Authentication</strong>
+ </a>
+ Specification
+ </li>
+ <li>
+ <a href="http://www.rfc-editor.org/rfc/rfc2109.txt">
+ <strong>State
+ Management Mechanism</strong>
+ </a>
+ Specification (Cookies)
+ </li>
+ </ul>
+ </subsection>
+
+ <a name="cycle"/>
+ <subsection name="0.3 The HTTP Request/Response cycle">
+
+ <p>A very important part of HTTP for the web developer is the
+ request/response cycle. To use HTTP
+ you have to make a request. A HTTP server, like a web
+ server, is then obliged to respond. When you
+ build your web application, you design it to react to a
+ HTTP request by returning a HTTP response.
+ Frameworks abstract much of these nuts and bolts, but it
+ is important to understand
+ what is happening behind the scenes.</p>
+
+ <p>If you are not familiar with the HTTP request/response
+ cycle, we
+ <strong>strongly</strong>
+ recommend the
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/HTTP.html#63796">
+ HTTP Overview</a>
+ in the Java Web Services Tutorial.
+ </p>
+
+ </subsection>
+
+ <a name="java"/>
+ <subsection
+ name="0.4 The Java Language and Application Frameworks">
+
+ <p>The framework is written in the popular and versatile
+ <a href="http://java.sun.com/docs/books/jls/first_edition/html/index.html">
+ Java programming language</a>
+ .
+ Java is an object-orientated language, and the framework
+ makes good use of many
+ object-orientated techniques. In addition, Java natively
+ supports the
+ concept of
+ <em>threads</em>
+ , which allows more than one task to be
+ performed at the same time. A good understanding of Java,
+ and especially
+ object-orientated programming (OOP) and threading, will
+ help
+ you get the most out of the framework and this User Guide.
+ </p>
+
+ <p>For more about Java and threads, see</p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/docs/books/tutorial/java/index.html">
+ <strong>Learning the Java Language</strong>
+ </a>
+ in the Java Tutorial
+ </li>
+ <li>
+ <a href="http://java.sun.com/docs/books/tutorial/essential/threads/index.html">
+ <strong>Threads: Doing Two or More Tasks At
+ Once</strong>
+ </a>
+ in the Java Language
+ Tutorial
+ </li>
+ </ul>
+
+ <p>Even if you have worked with Java and OOP before, it can
+ also help to be aware of the
+ programming challenges specific to creating and using
+ application frameworks. For more about application
+ frameworks, see the classic white papers</p>
+
+ <ul>
+ <li>
+ <a href="http://www.laputan.org/drc/drc.html">
+ <strong>Designing Reusable Classes</strong>
+ </a>
+ by Ralph E. Johnson & Brian Foote
+ </li>
+ <li>
+ <a href="http://www.cs.wustl.edu/~schmidt/CACM-frameworks.html">
+ <strong>Object-Oriented Application
+ Frameworks</strong>
+ </a>
+ by Mohamed Fayad and Douglas C. Schmidt
+ </li>
+ </ul>
+
+ <p>These papers can be especially helpful if you are
+ fact-finding or reviewing server-side
+ <a href="http://directory.google.com/Top/Computers/Programming/Languages/Java/Server-Side/Libraries_and_Frameworks/">
+ frameworks</a>
+ .
+ </p>
+
+ </subsection>
+
+ <a name="chain"/>
+ <subsection name="0.4.1 Chain of Responsibility">
+
+ <p>
+ A popular technique for organizing the execution of
+ complex
+ processing flows is the "Chain of Responsibility" pattern,
+ as described (among many other places) in the classic
+ <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0201633612/apachesoftwar-20/">
+ "Gang of Four" design patterns book.</a>
+ .
+ The GoF summarizes the Chain of Responsibility pattern as
+ "Avoid coupling the sender of a request to its receiver
+ by giving more than one object a chance to handle the
+ request.
+ Chain the receiving objects
+ and pass the request along the chain until an object
+ handles it."
+ </p>
+
+ <p>
+ The CoR pattern helps us keep software components loosely
+ coupled.
+ A component can call a Chain of Responsbility,
+ without knowing what objects are on the chain or how they
+ are
+ implemented.
+ Most importantly, we can adjust the Chain without changing
+ how callers invoke the Chain.
+ As of version 1.3,
+ the default Request Processor,
+ which acts as the framework's "kernal",
+ is a Chain of Responsiblity.
+ </p>
+
+ <p>
+ To implement its Chain, the Request Processor uses the
+ <a href="http://jakarta.apache.org/commons/chain/">
+ Chain of Responsibility</a>
+ component in the Jakarta Commons
+ which provides a standard implementation of the CoR
+ pattern,
+ along with various implementations of the Context and
+ Command objects used by the Chain to service a request.
+ </p>
+
+ <p>
+ For more about Chain of Responsiblity, see
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://jakarta.apache.org/commons/chain/">
+ Jakarta Commons Chain of Responsibility</a>
+ </li>
+ <li>
+ <a href="http://www.onjava.com/lpt/a/5671">
+ A look at Commons Chain</a>
+ </li>
+ <li>
+ <a href="http://www.infonoia.com/en/content.jsp?d=inf.05.06&pr=1">
+ Better Code with Struts 1.3
+ </a>
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="javabeans"/>
+ <subsection name="0.5 JavaBeans">
+
+ <p>Like many Java applications, most of the framework objects
+ are designed as
+ <a href="http://java.sun.com/products/javabeans/">
+ JavaBeans</a>
+ . Following the JavaBean design patterns makes
+ the framework's classes easier to use -- both by Java
+ developers and by Java development tools.
+ </p>
+
+ <p>Although JavaBeans were first created for visual elements,
+ these object design patterns have been found to
+ be useful as the basis for any reusable component, like
+ those used by the framework.</p>
+
+ <p>For more about JavaBeans, see:</p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/products/javabeans/docs/">
+ <strong>The
+ JavaBeans Component Architecture
+ Documentation</strong>
+ </a>
+ page at
+ <code>java.sun.com</code>
+ , including a link to download the
+ <a href="http://java.sun.com/products/javabeans/docs/spec.html">
+ JavaBeans 1.01 Specification</a>
+ </li>
+ <li>
+ <a href="http://java.sun.com/docs/books/tutorial/javabeans/index.html">
+ <strong>The JavaBeans Trail</strong>
+ </a>
+ in the Java Tutorial
+ </li>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSPBeans.html">
+ <strong>JavaBeans Components in JSP Pages</strong>
+ </a>
+ in the Java Web Services Tutorial
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="reflection"/>
+ <subsection name="0.5.1 Reflection and Introspection">
+
+ <p>
+ Reflection is the process of determining which member
+ fields and methods are available on an object.
+ Introspection is a specialized form of reflection used by
+ the JavaBean API.
+ Using Introspection, we can determine which methods of a
+ JavaBean are intended to be accessed by other objects.
+ (The getters and the setters, for example.)
+ </p>
+
+ <p>
+ The framework uses Introspection to convert HTTP
+ parameters into JavaBean properties and to populate HTML
+ fields from JavaBean properties.
+ This technique makes it easy to "roundtrip" properties
+ between HTML forms and JavaBeans.
+ </p>
+
+ <p>
+ For more about Reflection and Introspection, see
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/docs/books/tutorial/reflect/">
+ The Reflection Trail</a>
+ </li>
+ <li>
+ <a href="http://java.sun.com/products/javabeans/docs/spec.html">
+ Chapter 8 of the JavaBeans API Specification</a>
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="maps"/>
+ <subsection name="0.5.2 Maps">
+
+ <p>
+ JavaBeans store data as properties and may act on that
+ data through other methods.
+ JavaBeans are flexible and powerful objects but are not
+ the only object that programmers use to store data.
+ Another popular object is the Map [
+ <code>java.util.Map</code>
+ ].
+ A Map is a simple collection of name and value pairs.
+ Maps are often used "behind the scenes" as a flexible way
+ to store dynamic data.
+ </p>
+
+ </subsection>
+
+ <a name="dynabeans"/>
+ <subsection name="0.5.3 DynaBeans">
+
+ <p>
+ DynaBeans combine the extensibility of JavaBeans with the
+ flexibility of a Map.
+ Defining even the simplest JavaBean requires defining a
+ new class and coding a field and two methods for each
+ property.
+ The properties of a DynaBean can be configured via an XML
+ descriptor.
+ The virtual properties of a DynaBean can't be called by
+ standard Java methods,
+ but work well with components that rely on reflection and
+ introspection.
+ </p>
+
+ <p>
+ In your application, you can use DynaBeans to describe
+ your HTML forms.
+ This strategy can avoid creating a formal JavaBean
+ subclass to store a few simple properties.
+ </p>
+
+ <p>
+ For more about DynaBeans, see
+ </p>
+
+ <ul>
+ <li>
+ The Commons BeanUtils
+ <a href="http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/package-summary.html#package_description">
+ Package Description</a>
+ and
+ <a href="http://jakarta.apache.org/commons/beanutils/api/index.html">
+ Javadocs</a>
+ .
+ </li>
+ <li>
+ <a href="https://formdef.dev.java.net/">Struts
+ FormDef</a>
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="resources"/>
+ <subsection name="0.6 Properties Files and ResourceBundles">
+
+ <p>Java applications, including web applications, are often
+ configured using
+ <a href="http://java.sun.com/j2se/1.4.1/docs/api/java/util/Properties.html">
+ Properties</a>
+ files. Properties files are the basis for the
+ <a href="http://java.sun.com/j2se/1.4.1/docs/api/java/util/ResourceBundle.html">
+ ResourceBundles</a>
+ that the framework uses to provide message resources
+ to an application.
+ </p>
+
+ <p>For more about Properties files, see:</p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/docs/books/tutorial/essential/attributes/properties.html">
+ <strong>Using Properties to Manage Program
+ Attributes</strong>
+ </a>
+ in The Java Tutorial
+ </li>
+ </ul>
+
+ <p>Java ResourceBundles use one or more Properties files to
+ provide internationalized messages
+ to users based their
+ <a href="http://java.sun.com/j2se/1.4.1/docs/api/java/util/Locale.html">
+ Locale</a>
+ .
+ Support for localizing an application was built into the
+ framework from the ground-up.
+ </p>
+
+ <p>For more about localization and ResourceBundles, see</p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/docs/books/tutorial/i18n/resbundle/concept.html">
+ <strong>About the ResourceBundle Class</strong>
+ </a>
+ in the Java Tutorial
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="servlets"/>
+ <subsection name="0.7 Java Servlets">
+ <p>
+ Since Java is an object-orientated language, the
+ <a href="http://www.novocode.com/doc/servlet-essentials/">
+ Java Servlet</a>
+ platform strives to cast HTTP into an object-orientated
+ form.
+ This strategy makes it easier for Java developers to
+ concentrate on what they need their application to do --
+ rather than the mechanics of HTTP.
+ </p>
+
+ <p>
+ HTTP provides a standard mechanism for extending servers
+ called the Common Gateway Interface, or CGI.
+ The server can pass a request to a CGI-aware program, and
+ the program will pass back a response.
+ Likewise, a Java-aware server can pass a request to a
+ servlet container.
+ The container can fulfill the request or it can pass the
+ request back to the HTTP server.
+ The container decides whether it can handle the request by
+ checking its list of servlets.
+ If there is a servlet registered for the request, the
+ container passes the request to the servlet.
+ </p>
+
+ <p>
+ When a request comes in, the container checks to see if
+ there is a servlet registered for that request.
+ If there is a match,
+ the request is given to the servlet.
+ If not, the request is returned to the HTTP server.
+ </p>
+
+ <p>
+ It's the container's job to manages the servlet lifecycle.
+ The container creates the servlets, invokes the servlets,
+ and ultimately disposes the servlets.
+ </p>
+
+ <p>
+ A servlet is generally a subclass of
+ <code>javax.servlet.http.HttpServlet</code>
+ .
+ A servlet must implement four methods, which are invoked
+ by the container as needed:
+ </p>
+
+ <ul>
+ <li>
+ <strong>public void init(ServletConfig
+ config)</strong>
+ - Called by the
+ servlet container when the servlet instance is first
+ created, and
+ before any request is processed.
+ </li>
+ <li>
+ <strong>public void doGet(HttpServletRequest request,
+ HttpServletResponse response)</strong>
+ - Called to process a
+ specific request received using the HTTP
+ <code>GET</code>
+ protocol,
+ which generates a corresponding dynamic response.
+ </li>
+ <li>
+ <strong>public void doPost(HttpServletRequest request,
+ HttpServletResponse response)</strong>
+ - Called to process a
+ specific request received using the HTTP
+ <code>POST</code>
+ protocol,
+ which generates a corresponding dynamic response.
+ </li>
+ <li>
+ <strong>public void destroy()</strong>
+ - Called by the servlet
+ container when it takes this servlet instance out of
+ service,
+ such as when a web application is being undeployed or
+ when the
+ entire container is being shut down.
+ </li>
+ </ul>
+
+ <p>
+ The framework provides a ready-to-use servlet for your
+ application [
+ <code>org.apache.struts.action.ActionServlet</code>
+ ].
+ As a Struts developer, you can then just write objects
+ that the Struts ActionServlet calls when needed.
+ But it is still helpful to understand the basics of what
+ servlets are,
+ and the role they play in a Java web application.
+ </p>
+
+ <p>
+ For more about Java Servlets, see:
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/products/servlet/">
+ <strong>The
+ Java Servlet Technology</strong>
+ </a>
+ page at
+ <code>java.sun.com</code>
+ </li>
+ <li>
+ <a href="http://java.sun.com/products/servlet/download.html">
+ <strong>The
+ Servlet 2.2 and 2.3 Specifications</strong>
+ </a>
+ download page at
+ <code>java.sun.com</code>
+ </li>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets.html">
+ <strong>Java Servlet Technology</strong>
+ </a>
+ in the Java Web Services Tutorial.
+ </li>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/WebApp.html">
+ <strong>Web Applications</strong>
+ </a>
+ in the Java Web Services Tutorial.
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="threads"/>
+ <subsection name="0.7.1 Servlets and threads">
+
+ <p>
+ To boost performance, the container can multi-thread
+ servlets.
+ Only one instance of a particular servlet is created,
+ and each request for that servlet passes through the same
+ object.
+ This strategy helps the container make the best use of
+ available resources.
+ The tradeoff is that the servlet's
+ <code>doGet()</code>
+ and
+ <code>doPost()</code>
+ methods must be programmed in a
+ <em>thread-safe</em>
+ manner.
+ </p>
+
+ <p>
+ For more about servlets and thread-safety, see:
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets5.html#64386">
+ Controlling Concurrent Access to Shared
+ Resources</a>
+ in Java Web Services Tutorial.
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="context"/>
+ <subsection name="0.7.2 Servlet Context">
+
+ <p>The
+ <em>ServletContext</em>
+ interface [
+ <code>javax.servlet.ServletContext</code>
+ ] defines a servlet's view of
+ the web application within which the servlet is running.
+ It is
+ accessible in a servlet via the
+ <code>getServletConfig()</code>
+ method,
+ and in a JSP page as the
+ <code>application</code>
+ implicit variable.
+ Servlet contexts provide several APIs that are very useful
+ in building
+ Struts based web applications:
+ </p>
+ <ul>
+ <li>
+ <em>Access To Web Application Resources</em>
+ - A servlet can
+ access static resource files within the web
+ application using the
+ <code>getResource()</code>
+ and
+ <code>getResourceAsStream()</code>
+ methods.
+ </li>
+ <li>
+ <em>Servlet Context Attributes</em>
+ - The context makes available
+ a storage place for Java objects, identified by
+ string-valued keys.
+ These attributes are global to the entire web
+ application, and may
+ be accessed by a servlet using the
+ <code>getAttribute()</code>
+ ,
+ <code>getAttributeNames()</code>
+ ,
+ <code>removeAttribute()</code>
+ , and
+ <code>setAttribute()</code>
+ methods. From a JSP page, servlet
+ context attributes are also known as "application
+ scope beans".
+ </li>
+ </ul>
+
+ <p>
+ For more about the servlet context, see:
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets10.html#64724">
+ Accessing the Web Context</a>
+ in Java Web Services Tutorial.
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="request"/>
+ <subsection name="0.7.3 Servlet Request">
+
+ <p>Each request processed by a servlet is represented by a
+ Java
+ interface, normally a
+ <code>HttpServletRequest</code>
+ [
+ <code>javax.servlet.http.HttpServletRequest</code>
+ ].
+ The request interface provides an object-oriented
+ mechanism to access
+ all of the information that was included in the underlying
+ HTTP request,
+ including:
+ </p>
+ <ul>
+ <li>
+ <em>Cookies</em>
+ - The set of cookies included with this request
+ are available via the
+ <code>getCookies()</code>
+ method.
+ </li>
+ <li>
+ <em>Headers</em>
+ - HTTP headers that were included with
+ the request are accessible by name. You can enumerate
+ the names
+ of all included headers.
+ </li>
+ <li>
+ <em>Parameters</em>
+ - Request parameters, including those from
+ the query string portion of the URL and from the
+ embedded content
+ of the request (POST only) are available by name.
+ </li>
+ <li>
+ <em>Request Characteristics</em>
+ - Many other characteristics
+ of the incoming HTTP request, such as the method used
+ (normally
+ GET or POST) the protocol scheme used ("http" or
+ "https"), and
+ similar values.
+ </li>
+ <li>
+ <em>Request URI Information</em>
+ - The original request URI
+ being processed is available via
+ <code>getRequestURI()</code>
+ .
+ In addition, the constituent parts into which the
+ servlet container
+ parses the request URI (contextPath, servletPath, and
+ pathInfo) are
+ available separately.
+ </li>
+ <li>
+ <em>User Information</em>
+ - If you are using
+ <a href="#security">Container Managed Security</a>
+ , you can ask for
+ the username of the authenticated user, retrieve a
+ <code>Principal</code>
+ object representing the current user, and
+ whether the current user is authorized for a specified
+ role.
+ </li>
+ </ul>
+
+ <p>In addition, servlet requests support
+ <em>request attributes</em>
+ (from JSP, these are "request scope beans"), analogous to
+ the servlet
+ context attributes described above. Request attributes are
+ often used
+ to communicate state information from a business logic
+ class that
+ generates it to a view component (such as a JSP page) that
+ will use
+ the information to produce the corresponding response.
+ </p>
+
+ <p>The servlet container guarantees that a particular request
+ will
+ be processed by a servlet on a single thread. Therefore,
+ you do not
+ generally have to worry about the thread safety of your
+ access to
+ request properties and attributes.</p>
+
+ <p>
+ For more about the servlet request, see:
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets7.html#64433">
+ Getting Information from Requests</a>
+ in Java Web Services Tutorial.
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="response"/>
+ <subsection name="0.7.4 Servlet Response">
+
+ <p>The primary purpose of a servlet is to process an incoming
+ <a href="#request">Servlet Request</a>
+ [
+ <code>javax.servlet.http.HttpServletRequest</code>
+ ]
+ and convert it into a
+ corresponding response. This is performed by calling
+ appropriate
+ methods on the servlet response [
+ <code>javax.servlet.http.HttpServletResponse</code>
+ ]
+ interface. Available methods let you:
+ </p>
+ <ul>
+ <li>
+ <em>Set Headers</em>
+ - You can set HTTP headers that will be
+ included in the response. The most important header is
+ the
+ <code>Content-Type</code>
+ header, which tells your client what
+ kind of information is included in the body of this
+ response.
+ This is typically set to
+ <code>text/html</code>
+ for an HTML page,
+ or
+ <code>text/xml</code>
+ for an XML document.
+ </li>
+ <li>
+ <em>Set Cookies</em>
+ - You can add cookies to the current
+ response.
+ </li>
+ <li>
+ <em>Send Error Responses</em>
+ - You can send an HTTP error status
+ (instead of a usual page of content) using
+ <code>sendError()</code>
+ .
+ </li>
+ <li>
+ <em>Redirect To Another Resource</em>
+ - You can use the
+ <code>sendRedirect()</code>
+ method to redirect the client to
+ some other URL that you specify.
+ </li>
+ </ul>
+
+ <p>An important principle in using the servlet response APIs
+ is that
+ any methods you call to manipulate headers or cookies
+ <strong>MUST</strong>
+ be performed before the first buffer-full of
+ content has been flushed to the client. The reason for
+ this restriction
+ is that such information is transmitted at the beginning
+ of the HTTP
+ response, so trying things like adding a header after the
+ headers have
+ already been sent will not be effective.
+ </p>
+
+ <p>
+ When you are using presentation pages in a Model 2
+ application,
+ you will not generally use the servlet response APIs
+ directly.
+ In the case of JavaServerPages, the JSP page compiler
+ in your servlet container will convert your page into a
+ servlet.
+ The JSP servlet renders the response, interspersing
+ dynamic
+ information where you have interposed JSP custom tags.
+ </p>
+
+ <p>
+ Other presentation systems, like Velocity Tools for
+ Struts,
+ may delegate rendering the response to a specialized
+ servlet,
+ but the same pattern holds true.
+ You create a template,
+ and the dynamic response is generated automatically from
+ the template.
+ </p>
+
+ <p>
+ For more about the servlet response, see:
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets7.html#64531">
+ Constructing Responses</a>
+ in Java Web Services Tutorial.
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="filter"/>
+ <subsection name="0.7.5 Filtering">
+
+ <p>If you are using a servlet container based on version
+ <strong>2.3</strong>
+ or later of the Servlet Specification (such as
+ Tomcat 4.x), you can take advantage of the new Filter APIs
+ [
+ <code>javax.servlet.Filter</code>
+ ] that
+ let you compose a set of components that will process a
+ request or
+ response. Filters are aggregated into a chain in which
+ each filter
+ has a chance to process the request and response before
+ and after
+ it is processed by subsequent filters (and the servlet
+ that is ultimately
+ called).
+ </p>
+
+ <p>The Struts 1.0, 1.1, and 1.2 versions require only version
+ 2.2 or later
+ of the Servlet Specification to be implemented by your
+ servlet container,
+ so those versions do not use Filters. Beginning with the
+ 1.3 version, a container that supports version 2.3 or
+ later of the Servlet
+ Specification is required, and it is possible that the
+ framework might use
+ Filters in the future.</p>
+
+ <p>
+ For more about filters, see:
+ </p>
+
+ <ul>
+ <li>
+ <a href="http://java.sun.com/webservices/docs/1.0/tutorial/doc/Servlets8.html#64572">
+ Filtering Requests and Responses</a>
+ </li>
+ </ul>
+
+ </subsection>
+
+ <a name="session"/>
+ <subsection name="0.7.6 Sessions">
+
+ <p>One of the key characteristics of HTTP is that it is
+ <em>stateless</em>
+ . In other words, there is nothing built in to
+ HTTP that identifies a subsequent request from the same
+ user as being
+ related to a previous request from that user. This makes
+ building an
+ application that wants to engage in a conversation with
+ the user over
+ several requests to be somewhat difficult.
+ </p>
+
[... 502 lines stripped ...]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org