Java Reference
In-Depth Information
Figure 8-28.
Although this proves that the EnterEmpInfoForm Post request does invoke the doPost method, doPost doesn't
really do much. Let's modify doPost so that the form information is retrieved and then redisplayed.
Tutorial: Retrieving Form Information
In addition to enhancing the function of the servlet, we will also improve its structure. Notice that there is duplication
in MyServlet. For example, both do methods create print writer variables and set the response context. Couldn't the
context be set once and shouldn't we use one class print writer variable instead of two method variables? We will
create a new printer writer class variable and a new method called getStarted that will perform the common functions.
1.
Create a new method at the end of the class as follows:
public void getStarted(HttpServletResponse resp) throws
IOException {
}
The header must throw an IOException because the getOutputStream method (which we will use in this method)
can throw an IOException. Notice that the method also requires that the response be passed.
2.
Copy the first 4 statements from the doPost method into getStarted method.
 
Search WWH ::




Custom Search