By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 3,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

TOMCAT HELP... org.apache.jasper.JasperException:

P: n/a
Hi

I am writing a web based application as part of a small project that I
am undertaking using servlets beans and jsp.

I already have one servlet - bean - jsp page working and I have
written another servlet - bean - jsp but I am hitting an error from
tomcat that I have no idea why it is failing. I am getting an
org.apache.jasper.JasperException: with the root cause being
java.lang.ClassNotFoundException:

Here is the code for the servlet :

package platsWeb;

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import java.io.*;
import platsBeans.*;

public class joinGroup extends HttpServlet{
private platsWeb.dbConnection dbconn = new
platsWeb.dbConnection();
private ResultSet rs;

public void doPost(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException{
String group_id, user_id;
user_id = request.getParameter("user_id");
group_id = request.getParameter("group");

String joinGroup =("INSERT INTO groupusers(group_id,
user_id)VALUES("+group_id+","+user_id+");");
String selectUserData = ("SELECT user_id, firstname
FROM users"+
" WHERE user_id="+user_id+";");

String getGroup = ("SELECT * FROM `group` WHERE
group_id="+group_id+";");
groupBean gb = new groupBean();

String url =("/accountfinish.jsp");
dbconn.connect();
dbconn.insert_data(joinGroup);
request.setAttribute("groupbean", gb);
rs = dbconn.select_data(getGroup);
gb.setGroup(rs);
rs = dbconn.select_data(selectUserData);
gb.setUser(rs);
getServletConfig().getServletContext();
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
dbconn.close_connection();
}

}

and the bean:

package platsBeans;

import java.sql.*;

public class groupBean{
private ResultSet groupRS, userRS;
private String group_name, userfirstname;
private int user_id;

public void setGroup(ResultSet in){
System.err.println("setGroup GB");
groupRS = in;
}

public void setUser(ResultSet in){
System.err.println("setUser GB");
userRS = in;
}

public String getGroup(){
try{
groupRS.next();
group_name = groupRS.getString("groupName");
}catch(SQLException sqle){
System.err.println("SQLException: "+
sqle.getMessage());
}
return group_name;
}

public String getUser(){
try{
userRS.next();
userfirstname = userRS.getString("firstname");
}catch(SQLException sqle){
System.err.println("SQLException: " +
sqle.getMessage());
}
return userfirstname;
}

}

The code seems to be failing when I use the dispatcher to forward to
the new url???

Any help would be greatly received.

Thanks in advance

Grant Collins
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

A full stack trace leading to the exception would be useful.

Also- scoping your Connection object at the class level of your servlet is
dangerous. A servlet instance is typically shared by multiple clients.
"Grant Collins" <gc*********@yahoo.com> wrote in message
news:ga********************************@4ax.com...
Hi

I am writing a web based application as part of a small project that I
am undertaking using servlets beans and jsp.

I already have one servlet - bean - jsp page working and I have
written another servlet - bean - jsp but I am hitting an error from
tomcat that I have no idea why it is failing. I am getting an
org.apache.jasper.JasperException: with the root cause being
java.lang.ClassNotFoundException:

Here is the code for the servlet :

package platsWeb;

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import java.io.*;
import platsBeans.*;

public class joinGroup extends HttpServlet{
private platsWeb.dbConnection dbconn = new
platsWeb.dbConnection();
private ResultSet rs;

public void doPost(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException{
String group_id, user_id;
user_id = request.getParameter("user_id");
group_id = request.getParameter("group");

String joinGroup =("INSERT INTO groupusers(group_id,
user_id)VALUES("+group_id+","+user_id+");");
String selectUserData = ("SELECT user_id, firstname
FROM users"+
" WHERE user_id="+user_id+";");

String getGroup = ("SELECT * FROM `group` WHERE
group_id="+group_id+";");
groupBean gb = new groupBean();

String url =("/accountfinish.jsp");
dbconn.connect();
dbconn.insert_data(joinGroup);
request.setAttribute("groupbean", gb);
rs = dbconn.select_data(getGroup);
gb.setGroup(rs);
rs = dbconn.select_data(selectUserData);
gb.setUser(rs);
getServletConfig().getServletContext();
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
dbconn.close_connection();
}

}

and the bean:

package platsBeans;

import java.sql.*;

public class groupBean{
private ResultSet groupRS, userRS;
private String group_name, userfirstname;
private int user_id;

public void setGroup(ResultSet in){
System.err.println("setGroup GB");
groupRS = in;
}

public void setUser(ResultSet in){
System.err.println("setUser GB");
userRS = in;
}

public String getGroup(){
try{
groupRS.next();
group_name = groupRS.getString("groupName");
}catch(SQLException sqle){
System.err.println("SQLException: "+
sqle.getMessage());
}
return group_name;
}

public String getUser(){
try{
userRS.next();
userfirstname = userRS.getString("firstname");
}catch(SQLException sqle){
System.err.println("SQLException: " +
sqle.getMessage());
}
return userfirstname;
}

}

The code seems to be failing when I use the dispatcher to forward to
the new url???

Any help would be greatly received.

Thanks in advance

Grant Collins

Jul 17 '05 #2

P: n/a
Here is the full stack dump of the error that the site is
generating...

Also what would be the best way of creating the database connections?

Thanks for your help

Grant

================================================== =
org.apache.jasper.JasperException: platsBean.groupBean
at
org.apache.jasper.compiler.BeanRepository.getBeanT ype(BeanRepository.java:183)
at
org.apache.jasper.compiler.Generator$GenerateVisit or.visit(Generator.java:692)
at
org.apache.jasper.compiler.Node$GetProperty.accept (Node.java:552)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava:1028)
at
org.apache.jasper.compiler.Node$Visitor.visitBody( Node.java:1070)
at
org.apache.jasper.compiler.Node$Visitor.visit(Node .java:1076)
at org.apache.jasper.compiler.Node$Root.accept(Node.j ava:232)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava:1028)
at
org.apache.jasper.compiler.Generator.generate(Gene rator.java:1917)
at
org.apache.jasper.compiler.Compiler.generateJava(C ompiler.java:242)
at
org.apache.jasper.compiler.Compiler.compile(Compil er.java:369)
at
org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:473)
at
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:190)
at
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:295)
at
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:241)
at
javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at
org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:684)
at
org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatcher.java:432)
at
org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:356)
at platsWeb.createGroup.doPost(createGroup.java:51)
at
javax.servlet.http.HttpServlet.service(HttpServlet .java:760)
at
javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at
org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
at
org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2416)
at
org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:180)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:171)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:172)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
at
org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:174)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
at
org.apache.coyote.tomcat4.CoyoteAdapter.service(Co yoteAdapter.java:223)
at
org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:601)
at
org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:392)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:565)
at
org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:484)
root cause

java.lang.ClassNotFoundException: platsBean.groupBean
at
org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1444)
at
org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1289)
at
org.apache.jasper.compiler.BeanRepository.getBeanT ype(BeanRepository.java:181)
at
org.apache.jasper.compiler.Generator$GenerateVisit or.visit(Generator.java:692)
at
org.apache.jasper.compiler.Node$GetProperty.accept (Node.java:552)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava:1028)
at
org.apache.jasper.compiler.Node$Visitor.visitBody( Node.java:1070)
at
org.apache.jasper.compiler.Node$Visitor.visit(Node .java:1076)
at org.apache.jasper.compiler.Node$Root.accept(Node.j ava:232)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava:1028)
at
org.apache.jasper.compiler.Generator.generate(Gene rator.java:1917)
at
org.apache.jasper.compiler.Compiler.generateJava(C ompiler.java:242)
at
org.apache.jasper.compiler.Compiler.compile(Compil er.java:369)
at
org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:473)
at
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:190)
at
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:295)
at
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:241)
at
javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at
org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:684)
at
org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatcher.java:432)
at
org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:356)
at platsWeb.createGroup.doPost(createGroup.java:51)
at
javax.servlet.http.HttpServlet.service(HttpServlet .java:760)
at
javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at
org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
at
org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2416)
at
org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:180)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:171)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:172)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:641)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
at
org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:174)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invokeNext(StandardPipeline.j ava:643)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)
at
org.apache.coyote.tomcat4.CoyoteAdapter.service(Co yoteAdapter.java:223)
at
org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:601)
at
org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:392)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:565)
at
org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:484)

Jul 17 '05 #3

P: n/a
Grant--
<rant>
I don't mean to sound like a jerk, but you should really comply with
standard Java coding standards-- all Classes Should Start With A
Capital
Letter,
private platsWeb.dbConnection dbconn = new platsWeb.dbConnection();
just needs to be
private dbConnection dbconn = new dbConnection();
since you import platsWeb.* at the top.
String url =("/accountfinish.jsp");
should be
String url = "/acctionfinish.jsp";
and don't use the perl_naming_conventions, DoItLikeThisInstead()

Also, you should name your packages:
com.companyname.organizationname.whatever

Also, comment dammit!
</rant>

Ok, things to check for your JasperException:
1. Does the JSP get translated into a .java and then compiled into a
..class? If the JSP contains bad syntax, you'll get an error during the
forward.
2. Does /accountfinish.jsp actually exist? Can you get to it via
http://server/accountfinish.jsp?
3. Has any output been send to the client before the forward()?
4. Did you call getOutputStream() twice? You can only do it once. If
the
/accountfinish.jsp page does not NEED the original request/response,
then
just do a:
response.sendRedirect("/accountfinish.jsp");
instead.

Regards,
Michael Scovetta

Grant Collins <gc*********@yahoo.com> wrote in message news:<ga********************************@4ax.com>. ..
Hi

I am writing a web based application as part of a small project that I
am undertaking using servlets beans and jsp.

I already have one servlet - bean - jsp page working and I have
written another servlet - bean - jsp but I am hitting an error from
tomcat that I have no idea why it is failing. I am getting an
org.apache.jasper.JasperException: with the root cause being
java.lang.ClassNotFoundException:

Here is the code for the servlet :

package platsWeb;

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import java.io.*;
import platsBeans.*;

public class joinGroup extends HttpServlet{
private platsWeb.dbConnection dbconn = new
platsWeb.dbConnection();
private ResultSet rs;

public void doPost(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException{
String group_id, user_id;
user_id = request.getParameter("user_id");
group_id = request.getParameter("group");

String joinGroup =("INSERT INTO groupusers(group_id,
user_id)VALUES("+group_id+","+user_id+");");
String selectUserData = ("SELECT user_id, firstname
FROM users"+
" WHERE user_id="+user_id+";");

String getGroup = ("SELECT * FROM `group` WHERE
group_id="+group_id+";");
groupBean gb = new groupBean();

String url =("/accountfinish.jsp");
dbconn.connect();
dbconn.insert_data(joinGroup);
request.setAttribute("groupbean", gb);
rs = dbconn.select_data(getGroup);
gb.setGroup(rs);
rs = dbconn.select_data(selectUserData);
gb.setUser(rs);
getServletConfig().getServletContext();
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
dbconn.close_connection();
}

}

and the bean:

package platsBeans;

import java.sql.*;

public class groupBean{
private ResultSet groupRS, userRS;
private String group_name, userfirstname;
private int user_id;

public void setGroup(ResultSet in){
System.err.println("setGroup GB");
groupRS = in;
}

public void setUser(ResultSet in){
System.err.println("setUser GB");
userRS = in;
}

public String getGroup(){
try{
groupRS.next();
group_name = groupRS.getString("groupName");
}catch(SQLException sqle){
System.err.println("SQLException: "+
sqle.getMessage());
}
return group_name;
}

public String getUser(){
try{
userRS.next();
userfirstname = userRS.getString("firstname");
}catch(SQLException sqle){
System.err.println("SQLException: " +
sqle.getMessage());
}
return userfirstname;
}

}

The code seems to be failing when I use the dispatcher to forward to
the new url???

Any help would be greatly received.

Thanks in advance

Grant Collins

Jul 17 '05 #4

P: n/a

Hello again Grant-

I'm not exactly sure why you are getting the ClassNotFoundException for
class "platsBean.groupBean". Literally, this means that the class-loader
doesn't have anything that matches that name in its classpath. How do you
deploy your app? Do you have a WEB-INF directory on the server for this
application? If so, you should have the a "WEB-INF/classes/platsBean"
directory with a file called "groupBean.class". If not, then you should have
a ".jar" file in the "WEB-INF/lib" directory that contains a
"platsBean/groupBean.class" (along with the other files that you included in
the deployment archive.)

Michael's comments about code-style shouldn't be ignored either. The further
along you go, the more you'll appreciate not having to adjust to the
one-of-a-kind "accents" when trying to come up to speed with code that is
written by others (which can lead one to make dangerous assumptions about
what the variables in the code represent). It's hard enough to decipher the
code at hand without having to decipher the coder as well. A quick google
search for "java programming guidelines" will prove educational. There is no
"right" guideline, but there are standard meanings of capitilization that
help the reader know if they are dealing with instance variables, final
definitions, or classes themselves.
Also what would be the best way of creating the database connections?


If you're not up to speed with the concept of "Connection Pooling", then you
need to do some googling for that. Whenever you need a database connection,
you should retrieve it from a pool of already initialized Connections. You
should declare your database interaction objects (Connections, Statements,
ResultSets) outside the scope of a try-catch-finally block so that you can
ensure that all of the resources are cleaned up properly.

If you're not up to speed with the ideas of "Model View Controller"
application design, then off to google with you! Your app will quickly
collapse under it's own weight if you don't have clean separation of
concerns between discrete application layers. In other words, in a
well-designed system, you wouldn't typically want to have your servlet to
have to know about the internal details of your database schema.

Hope this helps,
Nicolas
Jul 17 '05 #5

P: n/a
On Sat, 6 Mar 2004 19:25:13 -0800, "Nicolas Dangre"
<pu****************@SPAMhotmail.com> wrote:

Hello again Grant-

I'm not exactly sure why you are getting the ClassNotFoundException for
class "platsBean.groupBean". Literally, this means that the class-loader
doesn't have anything that matches that name in its classpath. How do you
deploy your app? Do you have a WEB-INF directory on the server for this
application? If so, you should have the a "WEB-INF/classes/platsBean"
directory with a file called "groupBean.class". If not, then you should have
a ".jar" file in the "WEB-INF/lib" directory that contains a
"platsBean/groupBean.class" (along with the other files that you included in
the deployment archive.)
I have checked and the class file is in my WEB-INF/classes/platsBean
directory, so I can't understand why it is not working? However I
have now changed some of the code from response.forward(response,
request) to request.redirect(url) and now interestingly I am getting
a 404 error, yet the accountfinish.jsp page exists with the other jsp
pages.

Michael's comments about code-style shouldn't be ignored either. The further
along you go, the more you'll appreciate not having to adjust to the
one-of-a-kind "accents" when trying to come up to speed with code that is
written by others (which can lead one to make dangerous assumptions about
what the variables in the code represent). It's hard enough to decipher the
code at hand without having to decipher the coder as well. A quick google
search for "java programming guidelines" will prove educational. There is no
"right" guideline, but there are standard meanings of capitilization that
help the reader know if they are dealing with instance variables, final
definitions, or classes themselves.

Thanks for the tip, as you probably guessed I am new to this game so
any way of improving the way I develop applications is greatly
received.

Also what would be the best way of creating the database connections?


If you're not up to speed with the concept of "Connection Pooling", then you
need to do some googling for that. Whenever you need a database connection,
you should retrieve it from a pool of already initialized Connections. You
should declare your database interaction objects (Connections, Statements,
ResultSets) outside the scope of a try-catch-finally block so that you can
ensure that all of the resources are cleaned up properly.

If you're not up to speed with the ideas of "Model View Controller"
application design, then off to google with you! Your app will quickly
collapse under it's own weight if you don't have clean separation of
concerns between discrete application layers. In other words, in a
well-designed system, you wouldn't typically want to have your servlet to
have to know about the internal details of your database schema.

Hope this helps,
Nicolas


Thanks looked into it and I can see what where you are coming from
looks like I have some reworking of the application to do.

Thanks for all your help I have learnt a lot from all the pointers
that you have given me. Just need to find the error in the redirect
to the accountfinish.jsp and implement connection pooling.

Grant

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.