Java
  Home arrow Java arrow Page 2 - Developing JavaServer Pages
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
JAVA

Developing JavaServer Pages
By: Joel Murach
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 61
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Dell PowerEdge Servers

    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

    - 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...
    - Java Operators
    - Primitive Data Types and Basic Language Rule...
    - Java and Object-Oriented Programming
    - Java Beginning Programming
    - Gaming Development Setup
    - Using RPC-Style Web Services with J2EE
    - Integrating XML with J2EE
    - Taming Tiger: Concurrent Collections

    Iron Speed



    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway