• 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

Not able to get the last question

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am new to jsp. I have designed one program in jsp that it contains 5 questions. i did it using if loop. if i use jsp forward page, instead of displaying fifth question, it displays the forwarded page.
"quiz.jsp" is my page and if the last question comes, it has to go to the "handle.jsp" page. but i am not getting the last question. it displays the 4 th question and then to "handle.jsp"

here is my code..

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%!
int count=1;
Connection con=null;
Statement stmt=null;
ResultSet res=null;
%>
<html>
<body>
<form action="quiz.jsp">
<%
Object o=request.getAttribute("modern");
try
{
boolean ab=false;
if(count<=5)
{
class.forName();
...
...
<% if(count<5)
{
%>
<input type="submit" value="next">
<% } %>
<% if(count==5)
{
%>
<input type="submit" value="Submit">
<% ab=true;
} %>
<br></br>
<%
count++;
}
if(ab==true)
{
%>
<jsp:forward page="handle.jsp"/>
<% }
}
catch(Exception e)
{
System.out.println("Exception"+e);
}
%>
</form>
</body>
</html>
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
palmari,
Welcome to JavaRanch!


In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular, please see UseCodeTags.

You'll stand a much better chance of getting help if your code is easy to read.

As to your question:
I haven't gone through your logic completely so I can't tell you why you're not seeing the behaviour that you're expecting but I do see a much more serious problem.



Any variables declared inside the <%! ... %> block become instance variables. These variables are shared among all requests to your JSP (resulting in an app that is not thread safe).

This JSP may appear to be fine when you're the only one hitting it but it will show strange and erratic behaviour as soon as it starts handling multiple requests.
 
palmari sivasubramanian
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for your reply.
Give me some suggestions,how to handle this for multiple client requests.
which technology should i use?

Thanks in advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At a bare minimum, move all of your variable declarations into one of the service methods (doPost, doGet, etc...).

This will insure that you don't accidentally introduce threading errors into your code.

As you progress, you should take a look at container managed connection pooling. All spec compliant containers offer this feature. With it, you can configure the container (Tomcat, Websphere, etc..) to manage your database connections. In your code, you just ask the container for a connection and and hand it back when you're done. It's much cleaner and allows you to leverage all the hard work that others have spent insuring that the connection pool doesn't cause threading errors or memory leaks.

http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic