This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSP and the fly likes please help in simple jsp application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "please help in simple jsp application" Watch "please help in simple jsp application" New topic
Author

please help in simple jsp application

Achalveer Singh
Greenhorn

Joined: Sep 22, 2006
Posts: 25
hi all
i am using tomcat server and i am getting these error:
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NullPointerException
emp.Record.<init>(Record.java:32)
org.apache.jsp.WebRoot.showrecord_jsp._jspService(org.apache.jsp.WebRoot.showrecord_jsp:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264


i have three file
code for entrypage.jsp is


code for showrecord is:







code for Record.jsp


please tell me where is the error.
thanks
[ September 29, 2006: Message edited by: Ben Souther ]

ACHALVEER SINGH<br />SOFTWARE ENGINEER
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Achalveer Singh,
Welcome to Javaranch.

Before talking about your question I want to pass on this Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.



Now, to your question.
A NullPointerException (NPE) is something you should be able to find quickly, on your own. The Java runtime is very helpful in this respect.
org.apache.jsp.WebRoot.showrecord_jsp._jspService(org.apache.jsp.WebRoot.showrecord_jsp:76)

In this case, it's telling you that the NPE is on line 76 in the generated servlet code for your showrecord.jsp page.
Tomcat keeps its generated JSP/Servlet code under the {tomcat install}/work directory. You'll have to dive down through a series of directories to get to the actual source code.
IE: tomcat/work/Catalina/localhost/YOUR-APP/org/apache/jsp
.

Once you find the file, look at the line number mentioned and you will see what variables are being used on that line. This will give you a good starting point. Go back to your JSP code, find those variables and make sure they are not null before you try to call their methods.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Achalveer Singh
Greenhorn

Joined: Sep 22, 2006
Posts: 25
i have checked my code in generated servlet.
76 line is Record rr=new Record();

i am unable to inderstand what is the error.
Cm Ananth
Ranch Hand

Joined: Oct 20, 2005
Posts: 44
I guess you are pointing to some wrong line number, because during the object creation we will not get null pointer exception at all.. please verify.


By Ananth, Bangalore
Achalveer Singh
Greenhorn

Joined: Sep 22, 2006
Posts: 25
i have checked again

lines are
int id=Integer.parseInt(request.getParameter("id")); line no 75
Record rr=new Record(); 76
rr.setId(id); 77
ArrayList ar=rr.getAr(); 78
Iterator i=ar.iterator(); 79
while(i.hasNext())



but tomcat also showing java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver but i have included all things

please guide -----
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by CM Ananth:
I guess you are pointing to some wrong line number, because during the object creation we will not get null pointer exception at all.. please verify.


You will if the NullPointerException is happening in the object's constructor (or in this case, an init method called by the constructor):

java.lang.NullPointerException
emp.Record.<init>(Record.java:32)
org.apache.jsp.WebRoot.showrecord_jsp._jspService(org.apache.jsp.WebRoot.showrecord_jsp:76)


Achalveer,
What's on line 32 of Record.java?
Achalveer Singh
Greenhorn

Joined: Sep 22, 2006
Posts: 25
line no


e.printStackTrace();
}

}
public void setId(int id) line number 32
{
this.id=id;



but tomcat server shows error line 22:
line 22 is
Class.forName("").....

what can be error
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Achalveer Singh:

but tomcat server shows error line 22:


Where are you seeing this?

If you want strangers on a web-forum to help you, YOU have to make it really easy for them to do so.
If you're looking at a different stack trace than the one that you've posted, make sure you post the updated one as well.
Achalveer Singh
Greenhorn

Joined: Sep 22, 2006
Posts: 25
at stach trace it gives line at 32
but at console(black screen) it gives error at line 22

of Record.java
Rusty Smythe
Ranch Hand

Joined: Aug 09, 2006
Posts: 93

What if you try changing

to some known, valid value, e.g.,
Chetan Chauhan
Greenhorn

Joined: Oct 03, 2006
Posts: 8
Hello Achalveer,
i was going through your problem.
you were using Statement object and createStatement() methods in your code, which you shouldn'w because these doesn't support parameters i.e. usage of "where" clause in "select" query.
So instead use PreparedStatement object and then use prepareStatement() method to use "where" clause in "select" query.
i hope your problem will be solved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please help in simple jsp application