• 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

How to increment the value of request.getParameter?

 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to make an quiz and my query is ORDER BY RAND() so it means it will be random... My JSP send it to servlet to handle the flow but I'm having a problem, I have stored 4 questions with choices (answer) in the database and in my code below I retreive it. Problem is, when I retrieve the answer of the examinee the only retrieved data is the first answer... See my servlet


Servlet... Im just trying to experiment here but I really need help.. The output is null for the for and past code are also fail because the 1st answer is the olnly retrieve and I need to increment it. Please help

 
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is this line.



You are appending to the select element name. Thats why its giving null.
 
PeDz Momoshi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah... but how can I retrieve the other? the getParameter is not incrementing, the first answer is the only data I can retrieve... how can I do that?
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will currently get only a single value for all answers to all the questions. You probably need to send a unique select name (like select name="question#i") for each question. And then will have to identify the name on the server.

So something like this in your servlet,



For this to work, you have to add a temporary variable to your `while(rs.next())` and assign it to your select.

Something along the lines of,


Also remember this is a just quick and dirty way. Probably wait for other Ranchers; someone might point out a clean way of doing this.


 
PeDz Momoshi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh ok... but thankz... I appreciate your help..
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first, get rid of the scriptlets in the JSP. Use JSTL and EL to show your resultset.

Create a servlet where you preferably call a DAO method accessing the database and returning you your list of 'Answer' Objects, with a unique identifier. In the servlet, you set the list as a request attribute. Then you forward the request to your JSP, in which you iterate over your list using JSTL, and pass the identifier of the selected item to your next servlet.
 
PeDz Momoshi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you give me some codes? I'm not very sure how to do that.
 
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Googling you can find several examples of it.

here is one:

http://javaknowledge.info/?p=478
 
reply
    Bookmark Topic Watch Topic
  • New Topic