Home Answers Viewqa JSP-Servlet Problem to display checkbox item

 
 


rahul
Problem to display checkbox item
5 Answer(s)      2 years and 7 months ago
Posted in : JSP-Servlet

Hi, Following is my code:

<%@page import="java.sql.*"%> 
<h1>example.jsp</h1> 
<table border="1"> 
  <tr>
  <td></td> 
  <th>domainName</th> 
</tr> 
<% 
try{ 
Connection conn = null; 
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/entity","root", "rahul"); 
ResultSet rs = null; 
Statement st=null; 
st=conn.createStatement(); 
rs = st.executeQuery("select * from domain where categoryId=1"); 
while(rs.next()){ 
%> 

<tr>
<td>
    <input type="checkbox" name="check" 
    value=<%= rs.getString("domainId") %> 
    onClick="if (this.checked) {showState(this.value)()}" value="ON">
</td> 
<td><%= rs.getString("domainName") %></td> 

</tr> 

<% 
} 
}catch(SQLException e){ 
    System.out.println(e.getMessage()); 
} 
%>

<tr>
<td>
<input type=submit value="submit">
</td>
</tr>


</table>

I want to display records, when i click on submit button or any dumy button like submit.

for your info. In above code, it contains,

"domain" table containg three columns.

domainId--as number domainName--as string categoryId--as number

Plese, help me.

View Answers

October 20, 2010 at 4:43 PM


Hi Friend,

We have made changes in the code:

1)checkboxExample.jsp:

<%@page import="java.sql.*"%>
<head>  
 <script>  
 var xmlHttp;
var arr= new Array() ;
Array.prototype.clean = function(deleteValue) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == deleteValue) {         
      this.splice(i, 1);
      i--;
    }
  }
  return this;
};

 function showState(){ 

var total=""
for(var i=0; i < document.form.check.length; i++){
if(document.form.check[i].checked)
arr[i]=document.form.check[i].value;
}
arr.clean(undefined);
   if(typeof XMLHttpRequest != "undefined"){
   xmlHttp= new XMLHttpRequest();
   }
   else if (window.ActiveXObject){
   xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
   }
 if (xmlHttp==null){
    alert ("Browser does not support XMLHTTP Request")
 return
} 
var url= "gettable.jsp";
url += "?val=" +arr;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
 }
 function stateChange(){   
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){   
 document.getElementById("sel").innerHTML=xmlHttp.responseText;
 }
 }
 </script>  
 </head>
<form name="form">
<table border="1">
<tr><td></td>
<th>Id</th>
<th>Name</th>
<th>Address</th>
</tr>
<%
try{
Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
rs = st.executeQuery("select * from employee");
 while(rs.next()){ %>
<tr><td><input type="checkbox" name="check" value=<%= rs.getString("empid") %> ></td>
<td><%= rs.getString("empid") %></td>
<td><%= rs.getString("name") %></td>
<td><%= rs.getString("address") %></td>
</tr><%
}
}catch(SQLException e){ System.out.println(e.getMessage()); } %>
</table>
<input type="button" value="submit" onClick="showState();">
</form>
<br>
<br>
Selected Data<br>
<div id='sel'>  
</div>

October 20, 2010 at 4:44 PM


2) gettable.jsp:

<%@page language="java" import ="java.sql.*" %>  
 <%  
String val[] = request.getParameterValues("val");
String st="";
for(int i=0;i<val.length;i++){
    st+=val[i]+"";
}
    String str[]=st.split(",");
    for(int i=0;i<str.length;i++){
        System.out.println(str[i]);
    }
 ResultSet rs = null;
 String buffer="";  
 Class.forName("com.mysql.jdbc.Driver").newInstance();  
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
 Statement stmt = con.createStatement();  
 for(int i=0;i<str.length;i++){
     String ide=str[i];
     int id=Integer.parseInt(ide);
  rs = stmt.executeQuery( "SELECT * FROM employee WHERE empid='"+id+"'");  
   while(rs.next()){

   buffer=buffer+"<table border><tr><td>"+rs.getString("empid")+"</td><td>"+rs.getString("name")+"</td><td>"+rs.getString("address")+"</td></tr></table>"; 

   }
   }  
 response.getWriter().println(buffer);  
 %>

Thanks


October 20, 2010 at 6:42 PM


Thank you Deepak for your valuable reply...........:-) it really works

But,I want some more help from you.

In my program , i have given to link to different jsp pages. Suppose it contains two links with two different jsp pages.

Both jsp pages contains differents database tables, n it contains same checkboxes.

So, from your above code, i can display selected checkbox on same page. It works...

But when i go to another page link containing same format, it does not display previous page's selected checkboxes.

So, i want such output, which can show previous pages selected checkbox as well as i aslo include next page's selected checkbox in display list on same pages respectively.( i don't know exactly, but can we store it in session and in collection so that we can display all selected checkbox)

Please,please help me... waiting for your reply


October 20, 2010 at 7:46 PM


Thank you Deepak for your valuable reply...........:-) it really works

But,I want some more help from you.

In my program , i have given to link to different jsp pages. Suppose it contains two links with two different jsp pages.

Both jsp pages contains differents database tables, n it contains same checkboxes.

So, from your above code, i can display selected checkbox on same page. It works...

But when i go to another page link containing same format, it does not display previous page's selected checkboxes.

So, i want such output, which can show previous pages selected checkbox as well as i aslo include next page's selected checkbox in display list on same pages respectively.( i don't know exactly, but can we store it in session and in collection so that we can display all selected checkbox)

Please,please help me... waiting for your reply


October 21, 2010 at 11:46 AM


Hey please, help me.. i am new in java and jsp

please, send me modified code

waiting your reply









Related Pages:
Problem to display checkbox item
Problem to display checkbox item  Hi, Following is my code: <... include next page's selected checkbox in display list on same pages respectively.( i... can display all selected checkbox) Please,please help me... waiting for your
Adding checkbox to List as item
Adding checkbox to List as item   can we add checkox to List   Hi Friend, Try the following code: import java.awt.*; import javax.swing.... index = list.locationToIndex(event.getPoint()); CheckListItem item
Problem with DOJO tree with checkbox - Framework
Problem with DOJO tree with checkbox  Hi Friends, I have to generate a tree structure in a jsp along with checkbox besides each node. The tree... opens with tree structure. The checkbox will have 3 states: (1) partially
nested selected tag ihave display selected item
nested selected tag ihave display selected item   i have two combo...="2">UK etc in other combo box display all states relate first combo box, ok it can be done by creating array my problem is when i display data like
Dojo Tree With Checkbox - Framework
structure in a jsp along with checkbox besides each node. The tree structure... with tree structure. The checkbox will have 3 states: (1) partially checked, (2.... and after selecting the values I've to display those values in the parent page
Maintain checked checkbox status
Maintain checked checkbox status  Hi everyone In my JSP application, i have database table stored in mysql. when i display there recors using... display that "selected checked checkboxes" in same page but in another table
Checkbox pagination problem
Checkbox pagination problem  HI ., Following is my code test.jsp... Selected Domains " type=checkbox value="${domain.domainName}">... checkbox of table"Table Containts" and submit ">>" button, then in "Total
Display Problem
Display Problem  i am creating a small window application , i want to fetch data from ms-access(db) and want to display it on tables. what options are there to show result on table. is CSS helpfull
Checkbox Problem--Please Check this - JSP-Servlet
Checkbox Problem  I am facing a problem while creating a check box in JavaScript. Can any one share the part of code to create a checkbox in JavaScript
JSP CheckBox
JSP CheckBox          JSP CheckBox is used to create a CheckBox in JSP... checkbox and also print the userdefined message that specify the languages option
Item renderer in flex
Item renderer in flex  Hi..... I have a problem How do you call a method in particular ItemRenderer. Also the ItemRenderer is your own Custom Component? please give me an example for that...... Thanks
Item renderer in flex
Item renderer in flex  Hi..... How does item renderer work? How do I add item renderer at runtime? Please me the right answer so i cam implement this in my apps. Thanks  Ans: The base class for Spark item
print selected checkbox names in array without form tag
print selected checkbox names in array without form tag  Hi everyone ... I have problem in my program. I have hashmap i.e. collection , my...;% %> [/code] so, i want to display all
Display values in textbox on selecting checkbox
Display values in textbox on selecting checkbox Here we are going to perform action on selecting the checkbox and display the first five text box values into next five. We have ten text boxes and a checkbox. As the user enters value
Checkbox blocked - WebSevices
Checkbox blocked  Hi, i design online ticket reservation for bus. It contains no of seats. if i choose 3 or 4 seats checkbox,it will stored in my database. After i refreshing the page that checkbox seats are blocked
iterator display problem - Struts
iterator display problem   in action class i store database data in arrraylist but after success how can i display those data in jsp page using... friend, Code to help in solving the problem : Iterator Tag
Integer display problem
Integer display problem  class Bean{ int n1,n2; public Bean(){ } public Bean(int n1, int n2){ this.n1=n1; this.n2=n2; } public...); } } In above program value of n1 should display 10. But it is displaying 8. what
CheckBox in Flex
CheckBox item. <mx:CheckBox> tag is use to access this control. Like any...Flex CheckBox Control: The CheckBox control of Flex is a very common GUI, which is supported by almost every computer language. CheckBox control is used when
Display JSP selected listbox and checkbox in xml-please help me
Display JSP selected listbox and checkbox in xml-please help me  Hi... select something from 2nd list, third page contains checkbox which is taken from... ,it will stored in XML file and at same time ,it should display second page containing
checkbox
checkbox  how to insert multiple values in database by using checkbox in jsp
Jfreechart chart display problem
Jfreechart chart display problem  Using JSP and Jfreechart displays the chart fine on an internal browser in eclipse but doesnt display it on Chrome...) { System.out.println("Problem in creating chart."); } %> Stock1.jsp <
CheckBox in Flex4
CheckBox in Flex4: In Flex 4 the CheckBox Control is comprises from the components of both the MX and the Spark. We can use either MX CheckBox or Spark CheckBox both are same thing. Checkbox contains two part in a graphical shape
JavaScript Checkbox getElementById
(). This function allows to display an image if you clicked the checkbox... JavaScript Checkbox getElementById...() for checkbox in JavaScript. In the given example we are going to show an image
uploading problem
()) { FileItem item = (FileItem) itr.next...(); } } } } %> my problem...: firstly.... then problem solved... bt real problem is when i upload files fusing mozilla
Problem with display of images in applets - Applet
Problem with display of images in applets  Hi all, When I run... in figuring out the problem....  Hi frined, import java.applet.*; import..., this); } } --------------------------------------- Display image in Java Applet
how to insert the selected item of combobox in mysql - XML
how to insert the selected item of combobox in mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide... database.but after storing it has to display the alert box .like data has stored
select Query result display problem
select Query result display problem  Hi, String SQL_QUERY ="from Cc"; Query query = session.createQuery(SQL_QUERY); for(Iterator it=query.iterate();it.hasNext();){ Object[] row = (Object[]) it.next
popup window checkbox and sbumit button
popup window checkbox and sbumit button  Hi, Requirement: popup...; myStringArray.length; i++) { display=window.open('','NewWin','menubar...' size='2'><form>"; message+="<input type='checkbox' name
JComboBox Display Problem - Java Beginners
JComboBox Display Problem  I am create one program that contain two combo boxes. If first combo box i am display all date. If i select one date from first combo box then the second combo box display some dates based on first
Get specific item details by clicking on hyperlink
Get specific item details by clicking on hyperlink  sir, I am developing a shopping site, following is my problem definition: I have a search item button, if I click on that button it lists all items with item name
Item Renderer in AdvancedDataGrid
Item Renderer in AdvancedDataGrid: In this example you can see how we can use a item renderer property in AdvanceddataGrid control. The tag of item... a pie chart as a item renderer and displayed in AdvancedDataGrid. Example
Chart Item Event in Flex4
Chart Item Event in Flex4: Chart uses the ChartItemEvent when you perform the operation click on the chart Item. This event is the part of chart package... you will show the value of item when you click on the data item. If you click
insert data in the database using checkbox
the database using servlet on the jsp page and there is checkbox corresponding each row but the problem is that i am not fetching data in any textboxes so how...;input type="checkbox" name="check<%=i%>" value=<%= rs.getString("bookid
deleting messages using checkbox in JSP
deleting messages using checkbox in JSP  Am working on a Mail Server... is deleting correctly in my project. But Problem occurs when i use to delete...;input type="checkbox" name="inboxchk" value="<%=rs.getInt("omailid")%>">
deleting messages using checkbox in JSP
deleting messages using checkbox in JSP  Am working on a Mail Server... is deleting correctly in my project. But Problem occurs when i use to delete...;input type="checkbox" name="inboxchk" value="<%=rs.getInt("omailid")%>"><
Custom Item in J2ME
Custom Item in J2ME      ... and they can also set their look and feel as these custom item have their own method called paint(). Also CustomItem is a extendable class, and extends the Item class
Flex checkbox control example
Flex checkbox control example   ... checkbox control. Example is based on registration for online training courses... is demonstrated. Syntax for creating CheckBox control :   <mx:CheckBox/>
Skinning Data Item in Chart in Flex4
Skinning Data Item in Chart in Flex4: In this section you can see how we can provide the skin to data item in chart control. We will use the itemRenderer for providing the skin to data item. In this example we change
navigation between panels when item is selected from jcombobox - Swing AWT
navigation between panels when item is selected from jcombobox  hi well i have a problem i have one main panel and on that there is one more panel(2nd panel).the combo box is in main panel. when a item is selected from combobox
display records with images problem - JSP-Servlet
display records with images problem  hello, i am developing HR application whereby i want to display employee records and their pictures on web... with a unique id. Also i wrote i jsp that link to servlet in order to display
pbml in inserting selected item from combobox into mysql - XML
pbml in inserting selected item from combobox into mysql  hi, i have to insert the selected item from combobox into MYSQL database.pls provide... after storing it has to display the alert box .like data has stored
Dropdown Checkbox list
checkbox list</display-name> <welcome-file-list> <...Dropdown Checkbox list This tutorial explains how to create jquery Dropdown Checkbox list in JSP.  This example is created in eclipse IDE and run
loop problem - Java Magazine
); int your_choice = 0; do{ //display the main menu...? System.out.print("student ID saved. ");//display msg of std ID been saved. //return to main menu to select new item. //what loop to use? break
Display Tag
Display Tag  Hi Here is My code, There is problem At line no.3, where i want to display two fields in one column but it gives error.. Please any one knows the solution must reply Thanks In Advance
Display Tag
Display Tag  Hi Here is My code, There is problem At line no.3, where i want to display two fields in one column but it gives error.. Please any one knows the solution must reply Thanks In Advance
Returning data from an MX item editor in Flex4
. The default value of the editorDataField property is "text" and the item editor is a TextInput control. The tag of item editor is <mx:itemEditor>... item editor" width="428" height="234"> <
profile display
;<td ><b>Item Starts With</b></td> <td>: <input... * from item where name LIKE '"+name+"%'"; st = conn.createStatement(); ResultSet rs...;th>Row Num</th><th>Item Code</th><th>Item Name</th>
display checked ckeckbox in same jsp page
have displayed all values with checkbox in one table. Now i want to display...display checked ckeckbox in same jsp page  how to display checked ckeckbox in same jsp page?   Hi, Here is the html code to display check
Error display
Error display  I want to give a message on the screen that an error has occured...but I dont want to use alert and give pop up box...any other solution for the problem
how do i solve this problem?
how do i solve this problem?  Define a class named Circle with the following properties: List item An integer data field named radius... with the given radius value as the argument. A public method to display

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.