File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

checkbox in jsp

 
yash
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"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
 
DAYANAND BURAMSHETTY
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ 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
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic