• 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

Urgent Help Needed in JSP

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I am having a problem with checkboxes in JSP. I am displaying the checkboxes on one Jsp page.The number of checkboxes are not fixed they come from the database entries. When the user ticks on some checkboxes and clicks on the "BURROW" button, control is transferred to the next JSP page. where i can get the values of the ticked checkboxes. but the problem is that i want to restrict the user to tick only two checkboxes. How do i perform the validation in the second JSP page. I can get the number of checkboxes and pass the number to the next JSP page ..is there any mean by which i can use the isChecked() function to verify the checkbox? I have appended the code below ...Neglect the initial part ..just see the FORM part .

<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="login" class="WebSphereSamples.donttouchthis.Loginclass" scope="session" />
<jsp:useBean id="allow" class="WebSphereSamples.donttouchthis.Borrow" />
<html>
<body>
<% String thisuser= good.getUser();%>
<% boolean check= good.getGrant();%>
<%! ResultSet res;%>
<% if(check)
{ %>
<% String author=request.getParameter("aname");%>
<%res= allow.getAuthorBooks(author);%>
<b> The books written by </b><font color="pink" size=5><%= author%></font><b> are</b>
<br><br>

<form method="POST" action="Authornext.jsp">
<% int i=0;%>
<% while(res.next())
{

%>

     <input type="checkbox" name="<%= i%>" value="<%= res.getString(1)%>"><%= res.getString(1)%><br>

<% i=i+1;
} %>
<br>
<input type="hidden" name="hide" value="<%= i%>" >
<input type="submit" value="Borrow">

<br><br>
<b>Tick the Books you want to borrow</b><br>
<b> Note: </b> you can have atmost 2 books only<br>
</form>


<% }
else
{
response.sendRedirect("Relogin.jsp");
}

%>
</body>
</html>
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"dharmeshc",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Posts which contravene the naming convention are not eligible to win books! Please log in with a new name which meets the requirements.

Thanks.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use JavaScript to validate the contents of the checkboxes. See any good book on JavaScript for details.
If you want to stick with pure Java, you can retrieve the values of the checkboxes in the second JSP with request.getParameter() in a loop of i=0 to hide.
You have a problem, though, with your declaration of the result set:
<%! ResultSet res; %>
What happens when two people request your JSP at the same time? Remember, servlets are single instances with multiple threads, so any instance variables are shared - your second request will stomp on your first. You need to put this variable inside a scriptlet
<% ResultSet res; %>
so that it is a local method variable. If it needs to be shared between multiple pages in a session, you need to store it in the HttpSession:
<%
session.setAttribute("MyResultSet", res);
%>
...
<%
ResultSet res = (ResultSet) session.getAttribute("MyResultSet");
%>
Also, just out of curiosity, in what sense is this "urgent"?
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com
[This message has been edited by Phil Hanna (edited April 26, 2001).]
 
dharmeshc
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Phil
thanx for sharing your knowledge with me ... the mentioned problem was urgent cause i was not able to move ahead with my work .I was stuck with this thing for sometime ..but couldnt get the solution .
 
reply
    Bookmark Topic Watch Topic
  • New Topic