Java
  Home arrow Java arrow Page 2 - Developing JavaServer Pages
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
JAVA

Developing JavaServer Pages
By: Joel Murach
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 64
    2004-05-12


    Table of Contents:
  • Developing JavaServer Pages
  • The Code for the HTML Page that Calls the JSP
  • Imitating HTML
  • How to Create a JSP
  • How to Use the Methods of the Request Object
  • Retrieving Multiple Values
  • How to Request a JSP
  • Using Get and Post Methods
  • Using the Post Method
  • Managing Java Classes
  • Class Location

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Developing JavaServer Pages - The Code for the HTML Page that Calls the JSP
    ( Page 2 of 11 )

    Figure 2 presents the code for the HTML page that calls the JSP. If you've read chapter 3, you shouldn't have any trouble following it. Here, the Action attribute of the Form tag calls a JSP named show_email_entry.jsp that's stored in the same directory as the HTML page, and the Method attribute specifies that the HTTP Get method should be used with this action. Then, when the user clicks on the Submit button, the browser will send a request for the JSP.

    Figure 2: The code for the HTML page that calls the JSP

    <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <title>Chapter 4 - Email List application</title>
     </head>
       <body>
     <h1>Join our email list</h1>
       <p>To join our email list, enter your name and
         email address below. <br>
         Then, click on the Submit button.</p>

      <form action="show_email_entry.jsp" method="get">
      <table cellspacing="5" border="0">
        <tr>
          <td align="right">First name:</td>
          <td><input type="text" name="firstName"></td>
        </tr>
        <tr>
          <td align="right">Last name:</td>
          <td><input type="text" name="lastName"></td>
        </tr>
        <tr>
          <td align="right">Email address:</td>
          <td><input type="text" name="emailAddress"></td>
        </tr>
        <tr>
          <td></td>
          <td><br><input type="submit" value="Submit"></td>
        </tr>
      </table>
      </form>
     </body>
    </html>

    You should also notice the Name attributes of the three text boxes that are used in the table within this HTML page. These are the names of the parameters that are passed to the JSP when the user clicks on the Submit button. In Figure 1, the parameter names are firstName, lastName, and emailAddress and the parameter values are John, Smith, and jsmith@hotmail.com.

    Figure 3 presents the code for the JSP. As you can see, much of the JSP code is HTML. In addition, though, Java code is embedded within the HTML code in the form of JSP scriptlets and expressions. Typically, a scriptlet is used to execute one or more Java statements while a JSP expression is used to display text. To identify scriptlets and expressions, JSPs use tags. To distinguish them from HTML tags, you can refer to them as JSP tags.

    Figure 3: The Code for the JSP

    <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
     <head>
      <title>Chapter 4 - Email List application</title>
     </head>
    <body>

    < %
      String firstName = request.getParameter("firstName");
      String lastName = request.getParameter("lastName");
      String emailAddress = request.getParameter("emailAddress");
    % >

    <h1>Thanks for joining our email list</h1>
    <p>Here is the information that you entered:</p>
      <table cellspacing="5" cellpadding="5" border="1">
        <tr>
          <td align="right">First name:</td>
          <td><%= firstName %></td>
        </tr>
        <tr>
          <td align="right">Last name:</td>
          <td><%= lastName %></td>
        </tr>
        <tr>
          <td align="right">Email address:</td>
          <td><%= emailAddress %></td>
        </tr>
      </table>

    <p>To enter another email address, click on the Back <br>
    button in your browser or the Return button shown <br>
    below.</p>

      <form action="join_email_list.html" method="post">
      <input type="submit" value="Return">
      </form>

     </body>
    </html>

    Remember: this is from chapter four of Joel Murach's Java Servlets and JSP (Mike Murach & Associates, ISBN 1890774189, 2003). Grab a copy at your favorite book store today!

     Buy this book now.



     
     
    >>> More Java Articles          >>> More By Joel Murach
     

       

    JAVA ARTICLES

    - Exception Handling Techniques in Java
    - More About Multithreading in Java
    - The Basics of Multiple Threads in Java
    - Data Access Using Spring Framework JDBC
    - New Object Initialization in Java
    - Adding Images With iTextSharp
    - Adding Columns With iTextSharp
    - Creating Simple PDF Files With iTextSharp
    - The Spring Framework: Understanding IoC
    - Introducing the Spring Framework
    - Java Classes
    - Completing the Syntactic Comparison of Java ...
    - Syntactic Comparison of Java and C/C++
    - Java Statements
    - Conditionals, Expressions and Other Java Ope...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek