InfoCenter Home >
4: Developing applications >
4.2: Building Web applications >
4.2.2: Developing JSP files >
JSP code example - view employee records

JSP code example - view employee records


<HTML>
<HEAD>
<TITLE>JSP:  Add and View Employee Records</TITLE>
</HEAD>
<BODY>
<H1><CENTER>Add and View Employee Records</CENTER></H1>

<% String userID    = request.getParameter("USERID"); %>
<% String passWord  = request.getParameter("PASSWD"); %>

<%-- Get a connection to the Sample DB2 database using parameters from Login.jsp --%>

<tsx:dbconnect id="conn"  url="jdbc:db2:sample" driver="COM.ibm.db2.jdbc.app.DB2Driver">
<tsx:userid><%=userID%></tsx:userid>
<tsx:passwd><%=passWord%></tsx:passwd>
</tsx:dbconnect>

<FORM NAME="EmployeeForm" ACTION="employeeRepeatResults.jsp"
METHOD="post" ENCODE="application/x-www-form-urlencoded">
<h2>Add Employee Record</h2>
<P>To add a new employee record to the database, submit the following data:</P>

<TABLE>
<TR VALIGN="TOP" ALIGN="LEFT">
<TD><B><I>Employee Number:
<br>
(1 to 6 characters)</I></B></TD>
<TD>
<INPUT TYPE="text" NAME="EMPNO">
</TD>
</TR>

<TR VALIGN="TOP" ALIGN="LEFT">
<TD><B><I>First name:</I></B></TD>
<TD>
<INPUT TYPE="text" NAME="FIRSTNME" VALUE="First Name"><BR></TD>
</TR>

<TR VALIGN="TOP" ALIGN="LEFT">
<TD><B><I>Middle Initial:</I></B></TD>
<TD><INPUT TYPE="text" NAME="MIDINIT" VALUE="M"><BR></TD>
</TR>
<TR VALIGN="TOP" ALIGN="LEFT">
<TD><B><I>Last Name: </I></B></TD>
<TD><INPUT TYPE="text" NAME="LASTNAME" VALUE="Last Name"><BR></TD>
</TR>

<TR VALIGN="TOP" ALIGN="LEFT">
<TD>
<%-- Query the database to get the list of departments --%>
<tsx:dbquery id="qs" connection="conn" >
select * from DEPARTMENT
</tsx:dbquery>

<B><I>Department:</I></B></TD>
<TD>
<SELECT NAME="WORKDEPT" >
<tsx:repeat>
<OPTION VALUE= "<tsx:getProperty name="qs" property="DEPTNO" />" >
<tsx:getProperty name="qs" property="DEPTNAME" />
</tsx:repeat>
</SELECT>
</TD>
</TR>

<TR VALIGN="TOP" ALIGN="LEFT">
<TD><B><I>Education:</I></B></TD>
<TD>
<SELECT NAME="EDLEVEL">
<OPTION VALUE="1" SELECTED>BS
<OPTION VALUE="2">MS
<OPTION VALUE="3">PhD
</SELECT>
</TD>
</TR>
</TABLE>

<INPUT TYPE="submit" NAME="Submit" VALUE="Update">
<INPUT TYPE="hidden" NAME="USERID" VALUE="<%=userID%>">
<INPUT TYPE="hidden" NAME="PASSWD" VALUE="<%=passWord%>">
</FORM>
<HR>

<FORM NAME="EmployeeForm" ACTION="employeeRepeatResults.jsp"
METHOD="post" ENCODE="application/x-www-form-urlencoded">
<h2>View Employees by Department</h2>
<P>To view records for employees by department, select the department
and submit the query:</P>

<TABLE>
<TR VALIGN="TOP" ALIGN="LEFT">
<TD><B><I>Department:</I></B></TD>
<TD>
<%-- Use the bean generated by earlier QUERY tag --%>
<SELECT NAME="WORKDEPT" >
<tsx:repeat>
<OPTION VALUE= "<tsx:getProperty name="qs" property="DEPTNO" />" >
<tsx:getProperty name="qs" property="DEPTNAME" />
</tsx:repeat>
</SELECT>
</TD>
</TR>
</TABLE>

<INPUT TYPE="submit" NAME="Submit" VALUE="Query">
<INPUT TYPE="hidden" NAME="USERID" VALUE="<%=userID%>">
<INPUT TYPE="hidden" NAME="PASSWD" VALUE="<%=passWord%>">
</FORM>

<HR>
</BODY>
</HTML>

Go to previous article: JSP code example -  EmployeeRepeatResults Go to next article: JSP code example - login

 

 
Go to previous article: JSP code example -  EmployeeRepeatResults Go to next article: JSP code example - login