Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to increment the value of request.getParameter?  RSS feed

 
PeDz Momoshi
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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

 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
oh ok... but thankz... I appreciate your help..
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
can you give me some codes? I'm not very sure how to do that.
 
German Gonzalez-Morris
Ranch Hand
Posts: 299
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Googling you can find several examples of it.

here is one:

http://javaknowledge.info/?p=478
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!