19.09.2015 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

State<br />

<br />

Georgia-GA<br />

Oklahoma-OK<br />

Indiana-IN<br />

&nbsp;<br />

Zip <br />

<br />

<br />

<br />

<br />

<br />

* required fields<br />

<br />

<br />

<br />

Create the servlet named SimpleRegistration in Listing 42.7.<br />

Listing 42.7 SimpleRegistration.java<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

package chapter42;<br />

import javax.servlet.*;<br />

import javax.servlet.http.*;<br />

import java.io.*;<br />

import java.sql.*;<br />

public class SimpleRegistration extends HttpServlet {<br />

// Use a prepared statement <strong>to</strong> s<strong>to</strong>re a student in<strong>to</strong> the database<br />

private PreparedStatement pstmt;<br />

/** Initialize variables */<br />

public void init() throws ServletException {<br />

initializeJdbc();<br />

}<br />

/** Process the HTTP Post request */<br />

public void doPost(HttpServletRequest request, HttpServletResponse<br />

response) throws ServletException, IOException {<br />

response.setContentType("text/html");<br />

PrintWriter out = response.getWriter();<br />

// Obtain parameters from the client<br />

String lastName = request.getParameter("lastName");<br />

String firstName = request.getParameter("firstName");<br />

String mi = request.getParameter("mi");<br />

25

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

Saved successfully!

Ooh no, something went wrong!