19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The next request will submit the data back <strong>to</strong> the servlet. The servlet<br />

retrieves this hidden value just like any other parameter value, using<br />

the getParameter method.<br />

Let us use an example <strong>to</strong> demonstrate using hidden values in a form. The<br />

example creates a servlet that processes a registration form. The client<br />

submits the form using the GET method, as shown in Figure 42.21. The<br />

server collects the data in the form, displays them <strong>to</strong> the client, and<br />

asks the client for confirmation, as shown in Figure 42.22. The client<br />

confirms the data by submitting the request with the hidden values using<br />

the POST method. Finally, the servlet writes the data <strong>to</strong> a database.<br />

Figure 42.21<br />

The registration form collects user information.<br />

Figure 42.22<br />

The servlet asks the client for confirmation of the input.<br />

Create an HTML form named Registration.html in Listing 42.8 for<br />

collecting the data and sending it <strong>to</strong> the database using the GET method<br />

for confirmation. This file is almost identical <strong>to</strong> Listing 42.6,<br />

SimpleRegistration.html except that the action is replaced by<br />

Registration (line 9).<br />

Listing 42.8 Registration.html<br />

28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!