Java Reference
In-Depth Information
Tutorial: Database Access with Tags
We will demonstrate the flexibility and advantages of both the MVC architecture and custom tags by changing the
application to work with a DBMS. An Insert JSP (InsEmpInfo.jsp) will be created that allows a user to add employees
to the database and that uses the stateDDM custom tag. Two files (StartIEIF.html and EndIEIF) will be created that
define the beginning and ending of a form with all the needed data entry fields. New custom tags (insEmp, delEmp)
and tag handlers (InsertEmp, DeleteEmp) will be created to perform database inserts and deletions. InsEmpInfo.jsp
will use the Employee bean (created by the getEmp tag) and the insEmp and getEmp tags to insert the information.
Specifically, when InsEmpInfo.jsp is first accessed, a data entry form with the stateDDM field will be displayed.
After the information has been entered and the form's submit button clicked, InsEmpInfo will be invoked again.
InsEmpInfo will check to see if the request is a post and, if so, execute the getEmp tag (to create an Employee bean)
and the insEmp tag (to insert the information).
StartEEIF.html and EndEEIF.html have much of the HTML we need for the new form. Therefore, we will use them
as the base for StartIEIF.html and EndIEIF.html, thereby avoiding a lot of typing (and probably mistakes).
1.
In c11, copy and paste StartEEIF.html as StartIEIF.html and EndEEIF.html as EndIEIF.html.
StartIEIF needs to specify the form action as InsEmpInfo.jsp so that when the button is clicked, InsEmpInfo is
invoked again by the server. Also, the title should be changed to StartIEIF.html
2.
In the Source view of StartIEIF, change the TITLE and FORM tags to the following:
<title>StartIEIF.html</title>
<FORM action="InsEmpInfo.jsp" method="post">
EndIEIF needs to define the remaining data entry fields and the end of the form. Because EndEEIF was copied as
EndIEIF, the remaining data entry fields already exist in EndIEIF. However, the function options list box (i.e., display,
tax and gross amounts) is also in EndIEIF. So, the HTML that defines the table row holding the function list box and
text needs to be deleted.
3.
In the Source view of EndIEIF, delete the following HTML:
<tr>
<td align= "right" >
<font face= "Tahoma" size= "4" color= "black" >
Function
</font>
</td>
<td>
<select size= "2" name= "functionLB" >
<option value= "Display" >Display</option>
<option value= "Gross" >Gross</option>
<option value= "TaxAmt" >TaxAmt</option>
</select>
</td>
</tr>
4.
Change the Submit button's text from Submit to Insert.
The button start tag should look like the following:
<input type="submit" name="submitBtn" value="Insert">
5.
Save EndIEIF.
 
Search WWH ::




Custom Search