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).
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..
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.