Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Problem to display checkbox item
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rahul
Problem to display checkbox item
5 Answer(s)      4 years and 2 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.


Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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
checkbox
checkbox  how to insert multiple values in database by using checkbox in jsp
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
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...(request.getParameter("q")); String query="select dateof,dayinprice,company from stockprice
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
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
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
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
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.  The code for retrieving data from database into Drop Down List. <% DataSource data = new
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
Checkbox method
Checkbox method  what is the method to check if the checkbox is checked
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
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
UIButton checkbox
UIButton checkbox  iPhone UIButton checkbox example required.. can any one please explain me.. how to create a checkbox button using UIButton in XIB
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
Checkbox
Checkbox       A checkbox is again a label which is displayed as a pushbutton as shown in the example... of the checkbox is either true or false. However, the initial state is false
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
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
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
Ajax Checkbox
Ajax Checkbox  I want ajax code for checkboxes.The scenario is that if a selectbox is selected the corresponding values to it in the database table are to be checked in the checkbox.....Please do help me
return item in jquery
return item in jquery  How to return items/variables in JQuery?   See the code below to find out how to return an Item in Jquery: function findItem() { var item; while(if_item_not_found) { // search
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException
this code will be problem it display the error again send jsp for registration form
this code will be problem it display the error again send jsp for registration form  I AM ENTERING THE DETAILS OFTER IT DISPLAY THE ERROR PLEASE RESEND THE CODE org.apache.jasper.JasperException: java.lang.NumberFormatException
Advertisements
 

 

 

DMCA.com