Home arrow Java arrow Page 2 - JavaServer Pages, conclusion
JAVA

JavaServer Pages, conclusion


If you've taken a look at J2EE and JavaServer Pages technology, and want to examine JSP more closely, you've come to the right place. This article is the second of two parts, excerpted from chapter three of Beginning J2EE 1.4 From Novice to Professional, written by James L. Weaver, Kevin Mukhar, and Jim Crume (Apress, 2004; ISBN: 1590593413).

Author Info:
By: Apress Publishing
Rating: 4 stars4 stars4 stars4 stars4 stars / 17
November 10, 2005
TABLE OF CONTENTS:
  1. · JavaServer Pages, conclusion
  2. · The config Object
  3. · Try It Out: Using JavaBeans in JSP Pages
  4. · Translation and Compilation
  5. · The Deployment Descriptor
  6. · Including and Forwarding from JSP Pages
  7. · Summary

print this article
SEARCH DEVARTICLES

JavaServer Pages, conclusion - The config Object
(Page 2 of 7 )

This object is used to obtain JSP-specific init parameters. These initialization parameters are set in the deployment descriptor, but are specific to a single page. JSP init parameters are set in the <servlet> element of the deployment descriptor. This is because the page implementation class of the JSP (the Java class which is compiled from the JSP page) is a servlet class. The <servlet> element with the <init-param> element will look like this:

  <servlet>
    <servlet-name>StockList</servlet-name>
    <servlet-class>web.StockListServlet</servlet-class>
   <init-param>
      <param-name>name</param-name>
      <param-value>value</param-value>
    </init-param>
  </servlet>

See Chapter 5 for more information on how to use the <servlet> element.

If JSP initialization parameters are defined in the deployment descriptor, you can access them using:

config.getInitParameter(String name);

The exception Object

This implicit object is only available within error pages. It is a reference to the java.lang.Throwable object that caused the server to call the error page.

The application Object

This object represents the web application environment. You will use this object to get application-level configuration parameters. Within the deployment descriptor, you can set application parameters using this element:

  <webapp>
   
<context-param>
      <param-name>name</param-name>
      <param-value>value</param-value>
   
</context-param>
  </webapp>

The value of the parameter can be accessed using:

  application.getInitParameter(String name);

Scope

Objects that are created as part of a JSP have a certain scope, or lifetime. That scope varies with the object. In some cases, such as the implicit objects, the scope is set and cannot be changed. With other objects (JavaBeans for example), you can set the scope of the object. Valid scopes are page, request, session, and application.

  • page Page scope is the most restrictive. With page scope, the object is only accessible within the page in which it is defined. JavaBeans created with page scope and objects created by scriptlets are thread-safe. (Recall, though, that Java objects created by declaration elements are not thread-safe.)
  • request With request scope, objects are available for the life of the specific request. This means that the object is available within the page in which it is created, and within pages to which the request is forwarded or included. Objects with request scope are thread-safe. Only the execution thread for a particular request can access these objects.
  • session Objects with session scope are available to all application components that participate in the clients session. These objects are not thread-safe. If multiple requests could use the same session object at the same time, you must synchronize access to that object.
  • applicationThis is the least restrictive scope. Objects that are created with application scope are available to the entire application for the life of the application. These objects are not thread-safe and access to them must be synchronized if there is a chance that multiple requests will attempt to change the object at the same time.

     


blog comments powered by Disqus
JAVA ARTICLES

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials