• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

dynamic Checkboxe value retrieval

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all.. i am dynamically populating my jsp page table from database values with checkboxes in each row..i am not able to retrieve the checkbox value into my servlet even after using getparametervalues
its just not excuting..any solution ?
the value of the checkbox is dynamic data retrieved from the DB in each loop ...with same name ..help please
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, just to clarify:

You have some process which gets data from a database and, from that data, produces some HTML with checkboxes in it. You call that process "populating my JSP page table".

And in this HTML you have some link which is supposed to transmit the values of those checkboxes to a servlet.

Do I have this correct? If so then you have two separate steps; you should be able to examine them separately and determine which of the two steps is not working the way you want it to. This would be a better way to handle the problem than simply considering the whole thing as a big ball of mud.
 
vineet varghese
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you replying to my first post paul..
yes you got it right. the first part is working fine.i have all the DB details in my jsp page right now.
i just need to get all the "Checked box" values into my servlet on clicking submit button.this is where i am facing problem
any sample code will be helpful thank you.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want sample HTML code for sending checkbox data to a servlet? It would be more practical to look at your HTML code. So how about if we start from that?
 
vineet varghese
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
heres my jsp code....purchaseis my servlet where i want the checked box values...it may not be as efficient as i am new to this..thank you



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>

<%@page
import="com.online.vineetkirana.persistence.productsDAO"%>
<%@page
import ="com.online.vineetkirana.persistence.productsHibernateDAO"%>
<%@page
import="com.online.vineetkirana.vo.products"%>




<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Greefies Css Template</title>
<link rel="stylesheet" type="text/css" href="style/style.css" media="screen" />

</head>
<body>

<div id="main_container">
<!-- Common Include : start -->
<div id="header">
<div id="logo"><a href="home.html"><img src="images/logo.jpg" alt="" title="" border="0" /></a></div>
<jsp:include page="portal/common/menu.jsp"></jsp:include>
</div>
<jsp:include page="portal/common/header.jsp"></jsp:include>
<div id="main_content">
<jsp:include page="portal/common/productftSideBar.jsp"></jsp:include>
<!-- Common Include : end -->
<div id="right_content">
<!-- **********Main Body : Start*********** -->
<h2right>Welcome</h2right>

<div class="products_box">
<!-- Form : start -->
<!-- First part of : start -->
<p>

<form action="purchase" method="post" name="frm">
<input type="submit" size="30" name="sub" value="Create" />
<%
products us=new products();
productsDAO productdao =new productsHibernateDAO();

List <products> ufo= productdao.getAll_products();



out.println("<table border=1 style=\"margin-left: 82px;\">");
out.print("<th><b>ID </th>");
out.print("<th><b>NAME </th>");
out.print("<th><b>CATEGORY </th>");
out.print("<th><b>PRICE </th>");



for(int i=0;i<ufo.size();i++)
{


out.println("<tr><td><b>" + ufo.get(i).getProductid()+ "</td><td><b>" + ufo.get(i).getName() +"</td><td><b>" + ufo.get(i).getType()+"</td><td><b>"+ufo.get(i).getRate());
out.println("<td><b><input type=\"checkbox\" name=\"productname\" style=\"margin-left: 22px;\"value=ufo.get(i).getName()<b></b>/</td>");
out.println("<td><b><input type=\"checkbox\" name=\"productname\" style=\"margin-left: 22px;\"value=24<b></b></td>");

}

out.print("</table>");

out.println("");
out.println("");
out.println("");
%>

</FORM>

</p>
<!-- First part of : End -->
</div>

</p>

</div>
</div><!--end of right content-->
<!-- **********Main Body : End*********** -->


<div style=" clear:both;"></div>
</div><!--end of main content-->


<jsp:include page="portal/common/footer.jsp"></jsp:include>



</div> <!--end of main container-->
</body>
</html>
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's extremely inefficient for somebody to go through that and try to guess what HTML it would generate. That's why I asked you to post the HTML code. Use the "display page source" feature of your browser to get it.
 
vineet varghese
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Greefies Css Template</title>
<link rel="stylesheet" type="text/css" href="style/style.css" media="screen" />

<script type="text/javascript">
function show_alert()
{
alert("Created sucessfuly ");
}
</script>
</head>
<body>





<div id="main_container">
<!-- Common Include : start -->
<div id="header">
<div id="logo"><a href="home.html"><img src="images/logo.jpg" alt="" title="" border="0" /></a></div>

<div id="menu">
<ul>
<li><a href="home.jsp" title="">Home</a></li>

<li><a href="shopping.jsp" title="">Shop Now</a></li>
<li><a href="#" title="">Order Status</a></li>
<li><a href="#" title="">Contact Us</a></li>
<li><a href="customerdetails.jsp" title=""></a></li>


</ul>
</div>
</div>
<div class="green_box">
<div class="clock">

<!-- <img src="images/clock.png" alt="" title="" /> -->
</div>
<div class="text_content">
<h1> GreenZone KiranaS </h1>
<p class="green">

</p>
</div>

<!-- <div id="right_nav">
<ul>
<li style="margin-left: 186px;">
<a title="" href="home.html"> Heloo </a>
</li>
<li style="margin-left: 186px;">
<a title="" href="home.html"></a>
</li>
<li style="margin-left: 186px;">
<a title="" href="home.html"></a>
</li>
<li style="margin-left: 186px;">
<a title="" href="home.html"></a>
</li>
<li style="margin-left: 186px;">
<a title="" href="home.html"></a>
</li>
</ul>
</div>
-->

</div><!--end of green box-->
<div id="main_content">

<div id="left_content">
<h2left>Welcome </h2left>
<p>

</p>

<div id="left_nav">
<ul>
<li><a href="productadd.jsp" title="">Add New </a></li>
<li><a href="productdeleter.jsp" title="">Delete</a></li>

<li><a href="productlist.jsp" title="">View All Products</a></li>

</ul>
</div>

<p class="clear">


</p>

</div><!--end of left content-->
<!-- Common Include : end -->
<div id="right_content">
<!-- **********Main Body : Start*********** -->

<h2right>Welcome</h2right>

<div class="products_box">
<!-- Form : start -->
<!-- First part of : start -->
<p>

<form action="purchase" method="post" name="frm">
<input type="submit" size="30" name="sub" value="Create" />
<table border=1 style="margin-left: 82px;">
<th><b>ID </th><th><b>NAME </th><th><b>CATEGORY </th><th><b>PRICE </th><tr><td><b>1</td><td><b>kissan jam</td><td><b>breakfast</td><td><b>89

<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>2</td><td><b>honey</td><td><b>breakfast</td><td><b>33
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>3</td><td><b>katchup</td><td><b>breakfast</td><td><b>34
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>4</td><td><b>cornflakes</td><td><b>breakfast</td><td><b>34
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>5</td><td><b>kellogs</td><td><b>breakfast</td><td><b>77

<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>6</td><td><b>quaker oats</td><td><b>breakfast</td><td><b>100
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>7</td><td><b>kellogs honey</td><td><b>breakfast</td><td><b>29
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>8</td><td><b>kellogs honey</td><td><b>breakfast</td><td><b>44
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>9</td><td><b>dabur honey</td><td><b>breakfast</td><td><b>60

<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>10</td><td><b>rassam powder</td><td><b>cooking</td><td><b>45
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>11</td><td><b>everest garam masala</td><td><b>cooking</td><td><b>66
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>12</td><td><b>chiken masala</td><td><b>cooking</td><td><b>88
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>13</td><td><b>chat masala</td><td><b>cooking</td><td><b>30

<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>14</td><td><b>anjeer</td><td><b>Edibles</td><td><b>100
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>15</td><td><b>butter</td><td><b>Breakfast</td><td><b>30
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>16</td><td><b>butter</td><td><b>Breakfast</td><td><b>30
<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
<tr><td><b>17</td><td><b>butter</td><td><b>Breakfast</td><td><b>30

<td><b><input type="checkbox" name="productname" style="margin-left: 22px;"value=ufo.get(i).getName()<b></b></td>
</table>













</FORM>

</p>
<!-- First part of : End -->
</div>

</p>


</div>
</div><!--end of right content-->
<!-- **********Main Body : End*********** -->


<div style=" clear:both;"></div>
</div><!--end of main content-->


<div id="footer">


<ul>
<li><a href="#"></a> </li>

<li><a href="#"></a></li>
<li><a href="#"></a></li>
<li><a href=></a></li>
</ul>

</div>



</div> <!--end of main container-->
</body>
</html>


HOPE this is what you want
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. So when you look in that HTML and try to find a checkbox, this is what you find:

That wasn't what you intended to generate, was it?>
 
vineet varghese
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i intended the same html.
ufo.get(i).getName() gives me the data from the list that i fetched from the DB
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vineet varghese wrote:i intended the same html.
ufo.get(i).getName() gives me the data from the list that i fetched from the DB


Since this is the HTML source, if this statement ufo.get(i).getName() gives you a value, it has to be replaced by the value.
 
vineet varghese
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i am using a loop to fetch DB value and display the value on the page.
if i insert the value itself it wont be dynamic...right ?
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you misunderstood me!!!
when you have this

ufo.get(i).getProductid()

in your JSP, what is it displaying in your HTML source?? It is displaying the product id's 1,2,3...

Similarly when you have

ufo.get(i).getName()

in your JSP, when you view the HTML source the Name should be present there, instead you have the same ufo.get(i).getName()
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
replace this

out.println("<td><b><input type=\"checkbox\" name=\"productname\" style=\"margin-left: 22px;\"value=ufo.get(i).getName()<b></b>/</td>");

part of your JSP with this

out.println("<td><b><input type=\"checkbox\" name=\"productname\" style=\"margin-left: 22px;\"value="+ufo.get(i).getName()+"<b></b>/</td>");



I dont know for what purpose you are doing this, but using scriptlets is discouraged in a JSP.
 
vineet varghese
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thank you bhanu chowdary it worked
yes i know its not a good practice but i am not using it in many places ....mostly used servlet
thanks a lot....will get more doubts
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic