aspose file tools*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Urgent Help Needed in JSP" Watch "Urgent Help Needed in JSP" New topic
Author

Urgent Help Needed in JSP

dharmeshc
Greenhorn

Joined: Apr 16, 2001
Posts: 8
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>
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"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.


Read about me at frankcarver.me ~ 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
Website: http://www.philhanna.com
[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="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
dharmeshc
Greenhorn

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 .
 
Consider Paul's rocket mass heater.
 
subject: Urgent Help Needed in JSP