Jagadeesh M
asked on
java...jsp....delete record
this is my code snippet which lists all the users from a table...
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.lang.Integer" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.TreeMap" %>
<%@ page import="java.util.ArrayLis t" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome to Department of US Army - C4ISR</title>
<!-- Style Sheet -->
<link href="stylesheet.css" type="text/css" media="all" rel="stylesheet" />
<style type="text/css">
<!--
.style4 {
font-size: 16px;
font-weight: bold;
}
-->
</style>
</head>
<%
response.setHeader("Cache- Control"," no-store") ; //HTTP 1.1
response.setHeader("Pragma ","no-cach e"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<%
System.out.println("Now entered adminMain.jsp");
String req_count = (String)request.getAttribu te("req_co unt")==nul l?"0":(Str ing)reques t.getAttri bute("req_ count");
String errMsg = "";
%>
<body>
<!-- Header logo-->
<table width="100%" border="0">
<tr>
<td width="8%" height="57" rowspan="3"> </td>
<td width="92%"> </td>
</tr>
<tr>
<td height="10" style="font-family:arial;t ext-align: left;font- weight:bol d;padding: 3 0; margin-bottom:-1;"><span class="style4">Welcome to Department of US Army</span> </td>
</tr>
<tr>
<td><img src="Images/ArmySeal.gif" /></td>
</tr>
</table>
<!-- Header logo ends here-->
<hr color="#D0B623" />
<table border="0" cellspacing="0" class="form-noindent">
<tr>
<td colspan="4" class="color_D0B623">  ;</td>
</tr>
<tr>
<td height="17" colspan="3" valign="top" class="color_D0B623"> </td>
<td width="1073" rowspan="8" valign="top"><table width="100%" border="0" cellspacing="0">
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td width="2%" height="708"> </td>
<td width="96%" valign="top" class="headings"><p> List Of All Users </p>
<p>
<%
List searchMap = new ArrayList();
searchMap = (List)request.getAttribute ("searchMa p");
String tempData ="";
String tempData_Key = "";
if(searchMap == null || searchMap.size() == 0){
String errmsg = "Currently are no Temporary Requests for C4iSR - Suspense Tracking System";
%>
<h3 class="labeltxtb" align="center"><%out.write (errmsg);% ></h3>
<%} else{ %>
<table border="1" bordercolor="#D0B623" align="center" width="589" cellpadding="0" cellspacing="0" title="This table shows the results of the search query">
<tr class="labeltxtb">
<!-- Here Depending on the Option selected the sequence will be changed-->
<th>#</th>
<th>C4ISR ID </th>
<th>FIRST NAME </th>
<th>LASTNAME</th>
<th>EMAIL</th>
<th>START DATE </th>
<th>END DATE </th>
<th>CREATED ON</th>
<th>TYPE</th>
<th>DO THIS</th>
<% }%>
<%
Iterator i = searchMap.iterator();
int j = 1;
while(i.hasNext()){
Vector dataVector = (Vector)i.next();
if(dataVector !=null){
int dataVectorSize = dataVector.size();
String id=dataVector.get(0).toStr ing();
out.println("<tr>");
out.println("<td class=\"labeltxt\" align=\"center\" > ");
out.println(j);
out.println(" </td>") ;
j++;
for(int vectorIndex=0;vectorIndex< dataVector Size;vecto rIndex++){
tempData = dataVector.get(vectorIndex )==null ?"" :dataVector.get(vectorInde x).toStrin g();
if(vectorIndex==3)
tempData_Key = tempData;
out.println("<td class=\"labeltxt\" align=\"center\" > ");
out.println(tempData);
out.println(" </td>") ;
}// end of for loop
out.println("<td class=\"labeltxt\" align=\"center\" > ");
out.println("<a href=\"approveTempUser.jsp ?username= " + tempData_Key + "\" target=\"_self\"><font color=\"red\">" + "Delete" + "</font></a>");
out.println(" </td>") ;
out.println("</tr>");
}// end of if loop
else
out.println("Unable to retrieve the data properly. please contact system administrator");
}//end of while loop
%>
</table>
</td>
<td width="2%"> </td>
</tr>
<tr>
<td height="16" colspan="3" valign="top"> </td>
</tr>
</table>
<p> </p>
<p> </p></td>
</tr>
<tr>
<td width="24" height="98" class="color_D0B623">  ;</td>
<td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
<div align="center"><a href="#" >Add Suspense</a></div>
</li>
<li>
<div align="center"><a href="#">Search Suspense</a></div>
</li>
<li>
<div align="center"><a href="#">Generate Report</a></div>
</li>
<li>
<div align="center"><a href="#">Change Profile</a></div>
</li>
</ul>
</div></td>
<td width="24" height="98" class="color_D0B623">  ;</td>
</tr>
<tr>
<td height="18" colspan="3" class="color_D0B623">  ;</td>
</tr>
<tr>
<td width="24" height="98" class="color_D0B623">  ;</td>
<td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
<div align="center"><a href="#" >Authentication Requests (<font color="#FF0000"><b> <% out.println(req_count);%>< /b></font> ) </a></div>
</li>
<li>
<div align="center"><a href=ForwardToAddUser target="_self" >Add New User </a></div>
</li>
<li>
<div align="center"><a href="#">Delete/Deactivate User </a></div>
</li>
<li>
<div align="center"><a href="">View all Users </a></div>
</li>
</ul>
</div></td>
<td width="24" height="98" class="color_D0B623">  ;</td>
</tr>
<tr>
<td height="17" colspan="3" class="color_D0B623">  ;</td>
</tr>
<tr>
<td width="24" height="71" class="color_D0B623">  ;</td>
<td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
<div align="center"><a href=ForwardToAddChief target="_self" >Add Chief</a></div>
</li>
<li>
<div align="center"><a href="#">Delete/Deactivate Chief</a></div>
</li>
<li>
<div align="center"><a href="#">View all Chiefs </a></div>
</li>
</ul>
</div></td>
<td width="24" height="71" class="color_D0B623">  ;</td>
</tr>
<tr>
<td height="17" colspan="3" class="color_D0B623">  ;</td>
</tr>
<tr>
<td colspan="3"><p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p></td>
</tr>
</table>
<table width="100%" border="0">
<tr>
<td><div class="footer" >
<div align="center">©2006 US Army - <a href="#">Terms of Use</a> - <a href="#">Privacy Policy</a> </div>
</div> </td>
</tr>
</table>
<p> </p>
</body>
</html>
.......................... .....
at the end of each record...i'm having a link which says "Delete"..now when i click on this that particular record should be deleted from database. and i need to do this using servlet.
how can i take a key to identify the record to the servlet when it is in the form of link.... i know the other way around is using .jsp?key value.....which is currently used in the code as you see.....but want that aspect to be removed and replaced with a servlet concept....
thankz
<%@ page session="true" %>
<%@ page language="java" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.lang.Integer"
<%@ page import="java.util.HashMap"
<%@ page import="java.util.TreeMap"
<%@ page import="java.util.ArrayLis
<%@ page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome to Department of US Army - C4ISR</title>
<!-- Style Sheet -->
<link href="stylesheet.css" type="text/css" media="all" rel="stylesheet" />
<style type="text/css">
<!--
.style4 {
font-size: 16px;
font-weight: bold;
}
-->
</style>
</head>
<%
response.setHeader("Cache-
response.setHeader("Pragma
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<%
System.out.println("Now entered adminMain.jsp");
String req_count = (String)request.getAttribu
String errMsg = "";
%>
<body>
<!-- Header logo-->
<table width="100%" border="0">
<tr>
<td width="8%" height="57" rowspan="3"> </td>
<td width="92%"> </td>
</tr>
<tr>
<td height="10" style="font-family:arial;t
</tr>
<tr>
<td><img src="Images/ArmySeal.gif" /></td>
</tr>
</table>
<!-- Header logo ends here-->
<hr color="#D0B623" />
<table border="0" cellspacing="0" class="form-noindent">
<tr>
<td colspan="4" class="color_D0B623"> 
</tr>
<tr>
<td height="17" colspan="3" valign="top" class="color_D0B623"> </td>
<td width="1073" rowspan="8" valign="top"><table width="100%" border="0" cellspacing="0">
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td width="2%" height="708"> </td>
<td width="96%" valign="top" class="headings"><p> List Of All Users </p>
<p>
<%
List searchMap = new ArrayList();
searchMap = (List)request.getAttribute
String tempData ="";
String tempData_Key = "";
if(searchMap == null || searchMap.size() == 0){
String errmsg = "Currently are no Temporary Requests for C4iSR - Suspense Tracking System";
%>
<h3 class="labeltxtb" align="center"><%out.write
<%} else{ %>
<table border="1" bordercolor="#D0B623" align="center" width="589" cellpadding="0" cellspacing="0" title="This table shows the results of the search query">
<tr class="labeltxtb">
<!-- Here Depending on the Option selected the sequence will be changed-->
<th>#</th>
<th>C4ISR ID </th>
<th>FIRST NAME </th>
<th>LASTNAME</th>
<th>EMAIL</th>
<th>START DATE </th>
<th>END DATE </th>
<th>CREATED ON</th>
<th>TYPE</th>
<th>DO THIS</th>
<% }%>
<%
Iterator i = searchMap.iterator();
int j = 1;
while(i.hasNext()){
Vector dataVector = (Vector)i.next();
if(dataVector !=null){
int dataVectorSize = dataVector.size();
String id=dataVector.get(0).toStr
out.println("<tr>");
out.println("<td class=\"labeltxt\" align=\"center\" > ");
out.println(j);
out.println(" </td>")
j++;
for(int vectorIndex=0;vectorIndex<
tempData = dataVector.get(vectorIndex
if(vectorIndex==3)
tempData_Key = tempData;
out.println("<td class=\"labeltxt\" align=\"center\" > ");
out.println(tempData);
out.println(" </td>")
}// end of for loop
out.println("<td class=\"labeltxt\" align=\"center\" > ");
out.println("<a href=\"approveTempUser.jsp
out.println(" </td>")
out.println("</tr>");
}// end of if loop
else
out.println("Unable to retrieve the data properly. please contact system administrator");
}//end of while loop
%>
</table>
</td>
<td width="2%"> </td>
</tr>
<tr>
<td height="16" colspan="3" valign="top"> </td>
</tr>
</table>
<p> </p>
<p> </p></td>
</tr>
<tr>
<td width="24" height="98" class="color_D0B623"> 
<td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
<div align="center"><a href="#" >Add Suspense</a></div>
</li>
<li>
<div align="center"><a href="#">Search Suspense</a></div>
</li>
<li>
<div align="center"><a href="#">Generate Report</a></div>
</li>
<li>
<div align="center"><a href="#">Change Profile</a></div>
</li>
</ul>
</div></td>
<td width="24" height="98" class="color_D0B623"> 
</tr>
<tr>
<td height="18" colspan="3" class="color_D0B623"> 
</tr>
<tr>
<td width="24" height="98" class="color_D0B623"> 
<td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
<div align="center"><a href="#" >Authentication Requests (<font color="#FF0000"><b> <% out.println(req_count);%><
</li>
<li>
<div align="center"><a href=ForwardToAddUser target="_self" >Add New User </a></div>
</li>
<li>
<div align="center"><a href="#">Delete/Deactivate
</li>
<li>
<div align="center"><a href="">View all Users </a></div>
</li>
</ul>
</div></td>
<td width="24" height="98" class="color_D0B623"> 
</tr>
<tr>
<td height="17" colspan="3" class="color_D0B623"> 
</tr>
<tr>
<td width="24" height="71" class="color_D0B623"> 
<td width="206" valign="top"><div id="navcontainer">
<ul id="navlist">
<li >
<div align="center"><a href=ForwardToAddChief target="_self" >Add Chief</a></div>
</li>
<li>
<div align="center"><a href="#">Delete/Deactivate
</li>
<li>
<div align="center"><a href="#">View all Chiefs </a></div>
</li>
</ul>
</div></td>
<td width="24" height="71" class="color_D0B623"> 
</tr>
<tr>
<td height="17" colspan="3" class="color_D0B623"> 
</tr>
<tr>
<td colspan="3"><p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p></td>
</tr>
</table>
<table width="100%" border="0">
<tr>
<td><div class="footer" >
<div align="center">©2006 US Army - <a href="#">Terms of Use</a> - <a href="#">Privacy Policy</a> </div>
</div> </td>
</tr>
</table>
<p> </p>
</body>
</html>
..........................
at the end of each record...i'm having a link which says "Delete"..now when i click on this that particular record should be deleted from database. and i need to do this using servlet.
how can i take a key to identify the record to the servlet when it is in the form of link.... i know the other way around is using .jsp?key value.....which is currently used in the code as you see.....but want that aspect to be removed and replaced with a servlet concept....
thankz
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
# C4ISR ID FIRST NAME LASTNAME EMAIL START DATE END DATE CREATED ON TYPE DO THIS
1 michael.kasprowicz Michael Kasprowicz lkr3@njit.edu Apr-1-2006 Apr-16-2006 Jul-8-2006 12:40:08 AM Administrator Delete
2 jags_jm337 Jagadeesh Motamarri jm337@njit.edu Apr-1-2006 Apr-1-2007 Jul-8-2006 11:02:44 AM Temporary User Delete
3 kramagoni Kiran Kumar lkr3@njit.edu Apr-1-2006 Apr-1-2008 Jul-8-2006 11:05:51 AM Administrator Delete
4 steve.waugh Steve Waugh lkr3@njit.edu Mar-29-2008 Mar-27-2009 Mar-27-2006 05:50:27 PM Temporary User Delete
5 RichEgan Rich Egan jagadeesh.motamarri@gmail.
6 john.hughes John Hughes lkr3@njit.edu Mar-30-2006 Mar-30-2006 Jul-6-2006 03:56:52 PM Temporary User Delete