File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Incrementing value and reusing  jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Incrementing value and reusing  jsp page" Watch "Incrementing value and reusing  jsp page" New topic

Incrementing value and reusing jsp page

arjita mahajan

Joined: Nov 10, 2012
Posts: 11
I am creating a page which willl select 5 questions and option from a database and displays to user one by one(on click of next button).The answer is stored in database and in following jsp it is stored in ans[] variable (data extracted using JavaBean named Panchvi_pass).
My Code

The code above is working fine . But now I want that the answer that user enters is checked against ans[] and increments the marks if user enters correct answer. If i insert following line of code in above , it is giving me nullpoint exception..

please suggest me the correct soluion for this...
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63868

There are lots of problems with your page.

As we discussed elsewhere, you should no longer be using Java scriptlets in your JSPs. That's technology that has been obsolete and discredited for over 10 years.

But until you can wrap your mind around the JSTL and EL in place of scriptlets, here are a few major problems I see on ther page without even examining the code closely:

Use of declarations (<%! %>) create class-level variables! That's not thread-safe! That means that your page cannot be used by more than one user. Do you ever expect there to be more than once user of your site? If so, your page is unsuitable. You should never use declarations for read/write data -- it's not thread-safe.

The whole point of a JSP is to avoid creating markup in strings. This is completely inside out. Your markup should be outside of the scriptlet. Not embedded in a string inside a scriptlet, inside the JSP.

Let's start by fixing those problems and see where that takes you.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Incrementing value and reusing jsp page
It's not a secret anymore!