Java Reference
In-Depth Information
<tr><td> Author: </td>
<td><INPUT TYPE="text" NAME="author" ID="author"
SIZE="20" MAXLENGTH="20" ></td></tr>
<tr><td> Post text: </td>
<td><textarea cols="50" rows="5" wrap="soft"
name="postText"></textarea></td>
</tr>
<table>
<INPUT TYPE="hidden" NAME="parent"
value="<%=request.getParameter ("parent") %>" ID="parent" >
<INPUT TYPE="hidden" NAME="board"
value="<%=request.getParameter ("board") %>" ID="board" >
<INPUT TYPE="submit" NAME="Submit" ID="Submit" VALUE="Submit">
<INPUT TYPE="reset" NAME="Reset" ID="Reset" VALUE="Reset">
</P>
</FORM>
</BODY>
</HTML>
In this example, we could have easily used
HTML
instead of this
JSP
page. We
opted to use a
JSP
to assist with handling prepopulation of the form with
input parameters. We were also able to dynamically create the text that showed
the board. However, we have no controller or command, because this
JSP
data
does not need any input from command beans.
The model for AddPost
The following classes will take the user's responses on the
reply.jsp
form and
add them to the database. If we're successful, instead of returning a new
JSP
we'll return the user to the
ShowBoardResults.jsp
view via
ShowBoardCon-
troller
. Here is the
AddPostCommand
:
package bbs;
import java.io.*;
import java.sql.*;
import COM.ibm.db2.*;
import java.util.*;
public class AddPostCommand {
Here are the usual imports that we use in the rest of our commands:
private String author = null;
private String subject = null;
private String board = null;
private String parent = "0";
private String postText = null;
private ResultSet result;
private Connection connection = null;
private String query = null;