Developing JavaServer Pages - Using Get and Post Methods (Page 8 of 11 )
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

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.
Description
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. |
Next: Using the Post Method >>
More Java Articles
More By Joel Murach