Using a JSP to Create an HTML Form

Creating an HTML form using a JSP is just like creating a form using any other tool. JSP just gives you the ability to create form elements dynamically. An example of this would be to create a form to gather a user's name and shipping address. The dynamic part would be to have a default value for the user's company name, if the user has already logged in. Listing 12.1 contains a sample JSP that builds this type of form.

Code Listing 12.1. CreateForm.jsp
<html>
<head>
  <title>Create A JSP Form</title>
</head>

<body>

  <form action="/purejsp/RetrieveFormData.jsp" method="post">
    <table align="center" cellspacing="2" cellpadding="2" border="1">
      <tr>
        <td colspan="3">

        <b>Company:</b>
        <%
						String company = request.getParameter("company"); ...

Get Pure Java Server Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.