Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

java...jsp....delete record

Posted on 2006-04-01
2
Medium Priority
?
773 Views
Last Modified: 2011-10-03
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.ArrayList" %>
<%@ 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-cache"); //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.getAttribute("req_count")==null?"0":(String)request.getAttribute("req_count");
       String errMsg = "";
%>



<body>
<!-- Header logo-->
<table width="100%" border="0">
  <tr>
    <td width="8%" height="57" rowspan="3">&nbsp;</td>
    <td width="92%">&nbsp;      </td>
  </tr>
  <tr>
    <td height="10" style="font-family:arial;text-align:left;font-weight:bold;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">&nbsp;</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">&nbsp;</td>
      </tr>
      <tr>
        <td width="2%" height="708">&nbsp;</td>
        <td width="96%" valign="top" class="headings"><p> List Of All Users </p>
          <p>
            
             <%
                  List searchMap = new ArrayList();
                  searchMap = (List)request.getAttribute("searchMap");
                  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).toString();
                              out.println("<tr>");
                        
                                    
                              out.println("<td class=\"labeltxt\" align=\"center\" >&nbsp;");
                              out.println(j);
                              out.println("&nbsp;</td>");
                              j++;
                              for(int vectorIndex=0;vectorIndex<dataVectorSize;vectorIndex++){
                                    tempData = dataVector.get(vectorIndex)==null ?"" :dataVector.get(vectorIndex).toString();
                                    
                                    if(vectorIndex==3)
                                          tempData_Key = tempData;
                                          
                                    out.println("<td class=\"labeltxt\" align=\"center\" >&nbsp;");
                                    out.println(tempData);
                                    out.println("&nbsp;</td>");
                                    
                                    
                              }// end of for loop
                              

                              out.println("<td class=\"labeltxt\" align=\"center\" >&nbsp;");
                              out.println("<a href=\"approveTempUser.jsp?username=" + tempData_Key + "\" target=\"_self\"><font color=\"red\">" + "Delete" + "</font></a>");
                              out.println("&nbsp;</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%">&nbsp;</td>
      </tr>
      <tr>
        <td height="16" colspan="3" valign="top">&nbsp;</td>
      </tr>
    </table>
      <p>&nbsp;</p>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td width="24" height="98" class="color_D0B623">&nbsp;</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">&nbsp;</td>
  </tr>
  <tr>
    <td height="18" colspan="3" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td width="24" height="98" class="color_D0B623">&nbsp;</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">&nbsp;</td>
  </tr>
  <tr>
    <td height="17" colspan="3" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td width="24" height="71" class="color_D0B623">&nbsp;</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">&nbsp;</td>
  </tr>
  <tr>
    <td height="17" colspan="3" class="color_D0B623">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</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>&nbsp;</td>
  </tr>
</table>
<p>&nbsp; </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
0
Comment
Question by:jagadeesh_motamarri
2 Comments
 
LVL 10

Author Comment

by:jagadeesh_motamarri
ID: 16351862
sample table that gets displayed on jsp page....

# 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.com     Mar-27-2006     Mar-27-2007     Mar-27-2006 06:38:39 PM     Temporary User     Delete  
  6     john.hughes     John     Hughes     lkr3@njit.edu     Mar-30-2006     Mar-30-2006     Jul-6-2006 03:56:52 PM     Temporary User     Delete  


0
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 1500 total points
ID: 16352745
I think you can do this by using a hidden variable in the jsp. Just set this hidden variable value to the key value onClick of the Link using JavaScript and later in the servlet use request.getParameter of this hidden variable. tht will get you the key value based on which you can do the delete operation.

I think this will do if i have understood your question correctly.
:-)

Thank you.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question