Home arrow Java & J2EE arrow Page 8 - Developing JavaServer Pages

Using Get and Post Methods - Java

In this excerpt from chapter 4 of Joel Murach's Java Servlets and JSP, you'll learn how to develop a web application that consists of HTML pages and JavaServer Pages (JSPs). As you will see, JSPs work fine as long as the amount of processing that's required for each page is limited. When you complete this chapter, you should be able to use JSPs to develop simple web applications of your own.

  1. Developing JavaServer Pages
  2. The Code for the HTML Page that Calls the JSP
  3. Imitating HTML
  4. How to Create a JSP
  5. How to Use the Methods of the Request Object
  6. Retrieving Multiple Values
  7. How to Request a JSP
  8. Using Get and Post Methods
  9. Using the Post Method
  10. Managing Java Classes
  11. Class Location
By: Joel Murach
Rating: starstarstarstarstar / 65
May 12, 2004

print this article



When you code a Form tag that requests a JSP, you can code a Method attribute that specifies the HTTP method that's used for the request. The Get method is the default HTTP method, but the Post method is also commonly used.

Figure 8 presents the pros and cons of using the Get and Post methods. With either method, you can still test the page by appending the parameters to the URL string. So the question really comes down to selecting the appropriate method for the finished web application.

Figure 8: When to Use the Get and Post Methods

An HTML form tag that uses the Post method

<form action="show_email_entry.jsp" method="post">

A JSP Requested Through the Post Method

JavaServer Pages

When to Use the Get Method

  • If you want to transfer data as fast as possible.
  • If the HTML form only needs to transfer 4 KB of data or less.
  • If it's okay for the parameters to be displayed in the URL.
  • If you want users to be able to include parameters when they bookmark a page.

When to Use the Post Method

  • If you're transferring over 4 KB of data.
  • If it's not okay for the parameters to be appended to the URL.


The visible difference between the Get and Post methods is the URL that's displayed in the browser. For Get requests from an HTML page, the parameters are appended to the URL. For Post requests, the parameters are still sent, but they're not displayed in the browser.

You can test a JSP that uses either method by appending the parameters to the URL. 

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 & J2EE Articles          >>> More By Joel Murach

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates


Dev Shed Tutorial Topics: