|
|
| multiple dropdowns in single page |
Expert:mallika
i have a jsp page having drop down menus generated based on the number of request send and name of the drop down menu is status. Based on the request id the selected status of the drop down should be upadated in the database
intially for viewing the request iam using the below servlet
my jsp
<!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>Untitled Document</title> <link href="../css/css.css" rel="stylesheet" type="text/css" /> <%@ page import="java.util.*" import="java.io.*"%> </head>
<body>
<%String userType=(String)session.getAttribute("usertype");%> <%String fname=(String)session.getAttribute("fname");%> <%String lname=(String)session.getAttribute("lname");%> <%String mname=(String)session.getAttribute("mname");%> <%String NameOfCurrentUser=fname+" "+lname;%> <div id="content"> <form name="pendRequestForm" method="post" action="../Intranet"> <div id="adminevents"> <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">
<tr><td> <table width="100%" border="0" cellspacing="0" cellpadding="0" > <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="13" align="left"><img src="../images/round_left.gif" width="13" height="22" /></td> <td bgcolor="#5473A7" class="adminwhitehead" align="center">Requests</td> <td width="13" align="right"><img src="../images/round_right.gif" width="13" height="22" /></td> </tr> </table></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableborder"> <tr> <td> </td> </tr> <tr> <td align="center"> </td> </tr> <tr> <td align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="10%" class="loginhead1" align="center">Emp ID</td> <td width="19%" class="loginhead1" align="center">Name</td> <td width="27%" class="loginhead1" align="center">Request</td> <td width="14%" class="loginhead1" align="center">Type</td> <td width="19%" class="loginhead1" align="center">Received Date</td> <td width="11%" class="loginhead1" align="center" height="25px">status</td> </tr> <% ArrayList request_idList=new ArrayList(); ArrayList request_idList1=new ArrayList(); ArrayList AdminPendrequest = (ArrayList)session.getAttribute("AdminPendrequest"); if(AdminPendrequest!= null){ for(int i=0;i<AdminPendrequest.size();i++) { ArrayList records =(ArrayList) AdminPendrequest.get(i); request_idList.add((String)records.get(0)); request_idList1.add(request_idList); String request_id = (String)records.get(0); String emp_id = (String)records.get(1); String request_type = (String)records.get(2); String requested_date= (String)records.get(3); String requested_status=(String)records.get(4); String request_desc = (String)records.get(5); String name = (String)records.get(6); %> <tr> <td width="10%" class="login" align="center"><%=emp_id%></td> <td width="19%" class="login" align="center"><%=name%> <%=requested_status%></td> <td width="27%" class="login" align="center" valign="top"><%=request_desc%></td> <td align="center" class="login" ><%=request_type%></td> <td class="login" align="center"><%=requested_date%></td> <td width="11%" align="center" height="25px" valign="top"> <input type="hidden" name="reqId" value="<%=request_id%>"> <label> <select size="1" name="status"> <option selected><%=requested_status%></option> <%if(requested_status.equals("Open")){%> <option>Pending</option> <option>Deferred</option> <option>Closed</option> <%} else if(requested_status.equals("Pending")) {%> <option>Deferred</option> <option>Closed</option> <%} else if(requested_status.equals("Deferred")) {%> <option>Pending</option> <option>Closed</option> <%}%></select></label> </td> </tr><%}}session.setAttribute("request_idList1",request_idList1);%> <tr> <td> <input type="hidden" name="page" value="ModifyRequestStatus"> <input type="hidden" name="type" value="<%=userType%>"> <input type="hidden" name="CurrentUser" value="<%=NameOfCurrentUser%>"></td></tr>
</table></td> </tr> <tr> <td> </tr> <tr> <td> </td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="57%"> </td> <td width="43%" align="left"><a href="javascript:document.pendRequestForm.submit();"><img src="../images/update_btn.gif" /></a> <a href=""><img src="../images/closedrequest_btn.gif" /></a> <a href=""><img src="../images/back_btn.gif" /></a></td> </tr> </table></td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td bgcolor="#9CAFCD" class="topborder"> </td> </tr> </table></td> </tr> </table>
</td></tr> </table> </div> </form> </div> </body> </html>
servlet for view public class ViewAdminPendingRequests { public static void showRequests(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException { HttpSession session=request.getSession(); String empid=(String)session.getAttribute("empid"); if(empid==null) { response.sendRedirect("./pages/Logout.jsp"); } Statement stmt=null; Connection con1=null; ResultSet rs=null; ResultSet rs1=null; PreparedStatement ps=null; PreparedStatement ps1=null;
ArrayList AdminPendrequest=new ArrayList(); ArrayList NSDAdminPendRequest=new ArrayList(); ArrayList GeneralAdminPendrequest=new ArrayList(); String s1=""; String s=null; String userType=null; if(session.getAttribute("usertype")!=null) { userType=(String)session.getAttribute("usertype"); } System.out.println("USERTYPE---->"+userType);
String adminPendrequestSQL ="SELECT p1.pend_request_id,p1.emp_id,p1.pend_request_type,convert(VARCHAR(20),p1.pend_request_date,100),p1.pend_request_status,p1.pend_request_data,p2.first_name+' '+p2.last_name FROM PEND_REQUESTS p1,EMPLOYEE_DETAILS p2 where (p1.emp_id= p2.emp_id) AND(pend_request_status in('Open','Pending','Deferred'))";
try { con1=DBUtil.getconnection(); if(userType.equals("Admin")) { ps=con1.prepareStatement(adminPendrequestSQL); rs = ps.executeQuery(); while(rs.next()) { ArrayList adminpendrequestList=new ArrayList(); adminpendrequestList.add(rs.getString(1)); adminpendrequestList.add(rs.getString(2)); adminpendrequestList.add(rs.getString(3)); adminpendrequestList.add(rs.getString(4)); adminpendrequestList.add(rs.getString(5)); adminpendrequestList.add(rs.getString(6)); adminpendrequestList.add(rs.getString(7)); AdminPendrequest.add(adminpendrequestList); } } session.setAttribute("AdminPendrequest",AdminPendrequest); response.sendRedirect("./pages/adminPendingRequests.jsp"); }catch(Exception e) { System.out.println("exc-->"+e); } DBUtil.closeStatement(stmt); DBUtil.closeConnection(con1); DBUtil.closeResultSet(rs); } }
when i click on update the flowwing servlet is running package com.intranet.pending; import com.intranet.db.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; import java.sql.*;
public class ModifyPendingRequestStatus { public void modifyStatus(HttpServletRequest request,HttpServletResponse response) { HttpSession session=request.getSession();
ArrayList req_idList = (ArrayList)session.getAttribute("request_idList1");
/* for(int j=0;j<req_idList.size();j++) { ArrayList records =(ArrayList) AdminPendrequest.get(j); int request_id = Integer.parseInt((String)records.get(0)); } // int[] reqId=Integer.parseInt(req_idList[]); // System.out.println("reqid"+reqId);*/
String type=request.getParameter("type"); System.out.println("type"+type); String CurrentUser=request.getParameter("CurrentUser"); System.out.println("CurrentUser and reqid"+CurrentUser);
Connection con1=null; PreparedStatement pstmt=null; PreparedStatement pstmt2=null; String status=request.getParameter("status"); System.out.println("status111111"+status); try { con1=DBUtil.getconnection(); for(int i=0;i<req_idList.size();i++) { ArrayList records =(ArrayList) req_idList.get(i); int request_id = Integer.parseInt((String)records.get(0)); System.out.println("request_id"+request_id);
} if(status.equals("Closed")) { pstmt2=con1.prepareStatement("UPDATE PEND_REQUESTS SET pend_request_status='"+status+"',closed_by ='"+CurrentUser+"',respond_date=GetDate() WHERE pend_request_id=?"); pstmt2.setInt(1,35); pstmt2.executeUpdate(); System.out.println("updated status to in PEND_REQUEST table"+status); }else { pstmt = con1.prepareStatement("UPDATE PEND_REQUESTS SET pend_request_status='"+status+"',respond_date=GetDate() WHERE pend_request_id=? "); pstmt.setInt(1,35); pstmt.executeUpdate(); System.out.println("updated status to in PEND_REQUEST table"+status); } response.sendRedirect("./pages/adminPendingRequests.jsp"); } catch(Exception e){ System.out.println("exe-->"+e); }finally{ DBUtil.closeConnection(con1); DBUtil.closePreparedStatement(pstmt); DBUtil.closePreparedStatement(pstmt2); } } } every time i run the page only first id is getting modified can any one help me
Thanks in Advance |
| Answers |
Hi friend,
For read more information
http://www.roseindia.net/servlets/multiplemenu.shtml
Thanks
|
the link u sent was very help full thanks
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|