This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Servlets and the fly likes Urgent Help Needed in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Urgent Help Needed in JSP" Watch "Urgent Help Needed in JSP" New topic

Urgent Help Needed in JSP


Joined: Apr 16, 2001
Posts: 8
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 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" />
<% 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>

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


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

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

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

<% }

Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . 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.


Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
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
[This message has been edited by Phil Hanna (edited April 26, 2001).]

Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="" TARGET=_blank rel="nofollow">Instant Java Servlets</A>

Joined: Apr 16, 2001
Posts: 8
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 .
I agree. Here's the link:
subject: Urgent Help Needed in JSP
It's not a secret anymore!