wood burning stoves 2.0*
The moose likes Servlets and the fly likes checkbox in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "checkbox in jsp" Watch "checkbox in jsp" New topic
Author

checkbox in jsp

yash
Greenhorn

Joined: Aug 11, 2001
Posts: 1
hi to all
I provide a number of checkboxes in number of rows.If the user selects several checkbox and clicks on add button which i provide below, then the data on which those he selects the checkboxes must add to the database.This is same as to delete case also.How to send data to the database by selecting more than one checkbox
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

"yash"
your name doesn't seem to agree with the javaranch guidelines.
please take a moment and re-register after reviewing the guidelines at http:www/javaranch.com/name.jsp
thanks for your cooperation.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
DAYANAND BURAMSHETTY
Ranch Hand

Joined: Aug 06, 2001
Posts: 34
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page session = "true" %>
<%

Vector userVec=null;
//userVec getting from servlet(somewhereelse) for diaplaying all the records
userVec=(Vector)request.getAttribute("USERLIST");
%>
<html>
<head>
<title>Testing </title>
</head>

//UserSvc is servlet for adding or deleteting the records from table.
<form NAME="admin" action="/UserSvc" METHOD="POST" >
</table>
<table width=100% border="1" cellspacing="2" cellpadding="5" >
<tr>
<th width="20%" >User ID</th>
<th width="20%" >Full Name</th>
....
</tr>

<%
for( int i=0,Enumeration e=userVec.elements() ;e.hasMoreElements();i++){
//UserTB is accessor class means ... have setXXX() and getXXX() methods........
UserTB usertb = null;
String userId=null;
usertb=(UserTB)e.nextElement();
userId=(String)usertb.getUserId();
String fullName=(String)usertb.getFullName();

String hiddenFieldFullName="fullName"+i;

..
%>
<tr>
<td width="4%">
<input type="checkbox" name="USERID" value=<%=userId%> ></td>
<td width="20%" > <%=userId%> </td>
//If U need this value ...req.getPaarameter("fullNameX");//X=0,1,..or ..4
<input type="Hidden" name="<%=hiddenFieldFullName%>" value=<%=fullName%> > </td>
<td width="20%"> <%=fullName%> </td>
<%}%>
</tr>
</table>
<input type="submit" name="AddNew" value="Add New">
<input type="submit" name="DeleteChecked">
</form>
</body>
</html>
---------------------------------------------------------------------------
//UserSvc servlet file
public class RoleSvcServlet extends HttpServlet{
//Main(service) function

public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{
//This list(userId[]) getting from jsp
String[] userId= req.getParameterValues("USERID");
//This is for adding the new record
String addNew=(String)req.getParameter("AddNew");
if(addNew!=null){
String fullName=null;
String fullNameValue=null;
...
for(int i=0;i<userId.length;i++){
String fullName=null;
String fullNameValue=null;
fullName="fullName"+i;
fullNameValue=req.getParameter(fullName);
...addFunction(userId[i],fullNameValue....);
}

}else{
for(int i=0;i<userId.length;i++){
...deleteFunction(userId[i]);
}
//Ending delete
}
}//service
}

Dil se....,<BR>Dayanand<BR>0065-8839071(off)<BR>0065-7547034(Res0
 
Don't get me started about those stupid light bulbs.
 
subject: checkbox in jsp