[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

javax.servlet.ServletException: shop/ShoppingBasket (wrong name: ShoppingBasket)

Posted on 2009-02-12
16
Medium Priority
?
969 Views
Last Modified: 2013-11-24
Hi experts,
I am using jsp and tomcat to develop a shopping cart appln,
I have created two java ben classes ShoppingBasket,Product and placed them in
C:\Tomcat 5.5\webapps\ROOT\shop\WEB-INF\classes
I have included this directory to the classpath, but when i am accessing the bean from jsp i'm getting the following error
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: shop/ShoppingBasket (wrong name: ShoppingBasket)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NoClassDefFoundError: shop/ShoppingBasket (wrong name: ShoppingBasket)
      java.lang.ClassLoader.defineClass1(Native Method)
      java.lang.ClassLoader.defineClass(Unknown Source)
      java.security.SecureClassLoader.defineClass(Unknown Source)
      org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1650)
      org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:856)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1305)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1187)
      org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1210)
      org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
      org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
      org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
      org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
      org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
      org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
      org.apache.jasper.compiler.Generator.generate(Generator.java:3284)
      org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:189)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
      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)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.12

my jsp code is

<%@ page language="java" contentType="text/html" import="shop.shoppingBasket,shop.Product" errorPage="errorpage.jsp" %>
<html>
<head><title>Welcome to the shop </title></head>
<body>
<table width="385" border="0" cellspacing="0">
<tr><td colspan="4">More books from Mike McGrath:</td></tr>
<tr><td colspan="4" align="right">
<a href="<%= response.encodeURL("shop-basket.jsp")%>">
<img src="images\viewbasket.gif"></a></td></tr>
<tr>
<td><b>Ref</b></td><td><b>Title</b></td>
<td><b>Price</b></td><td></td></tr>
 
<% Class.forName("com.mysql.jdbc.Driver"); 
   java.sql.Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop","anu","kodanda");
   System.out.println("successful");
   java.sql.Statement stmt = connection.CreateStatement();
   java.sql.ResultSet RS = stmt.executeQuery("select * from items");
   
   int rowCounter=0;
   while(Rs.next())
   {
	   String item_id = Rs.getString("item_id");
	   String title = Rs.getString("title");
	   String description = Rs.getString("description");
	   String price = Rs.getString("price");
	   rowCounter++;
	   String bg =(rowCounter % 2 !=0)?"#C0C0C0":"FFFFFF";
>%
	   <tr bgcolor="<%= bg %>">
	   <td><%= item_id %></td>
	   <td><b><%= title %><b><br/><%=description %></td>
	   <td>£<%=price %></td>
	   <td>
	   <a href="<%= response.encodeUrl("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price)%>">
	   <img src ="images\addtobasket.gif"><a></td>
	   </tr>
<%  }RS.close(); connection.close();%>
</table>
<jsp:useBean id="basket" class="shop.ShoppingBasket" scope="session"/>
<% String title = request.getParameter("title");
	   if(title!=null)
	   {
		   String item_id = request.getParameter("item_id");
		   double price = Double.parseDouble(request.getParameter("price"));
		   Product item = new Product(item_id,title,price);
		   basket.addProduct(item);
	   }
%>
</body></html>
 
pls suggest me where I am wrong
thanks

Open in new window

0
Comment
Question by:APPIREDDY
  • 6
  • 5
  • 4
15 Comments
 
LVL 28

Expert Comment

by:rrz
ID: 23622459
>I have created two java ben classes ShoppingBasket,Product and placed them in
C:\Tomcat 5.5\webapps\ROOT\shop\WEB-INF\classes
If the first line in their source files is
package shop;
then put them into a folder called shop  and put that folder into  C:\Tomcat 5.5\webapps\ROOT\shop\WEB-INF\classes
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 23623366
>then put them into a folder called shop  and put that folder into  C:\Tomcat 5.5\webapps\ROOT\shop\WEB-INF\classes

I think rrz meant

  C:\Tomcat 5.5\webapps\ROOT\WEB-INF\shop\classes ( assuming your context for the web app is in root).
0
 
LVL 28

Expert Comment

by:rrz
ID: 23623479
Hi kuldeep, Thanks for the help.  But, no, that is not what I meant.  
I meant
C:\Tomcat 5.5\webapps\ROOT\shop\WEB-INF\classes\shop\ShoppingBasket.class
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 23623568
Yup I read your statement again.. create then in folder shop and put that "folder"...

thats what I missed while reading it..:)
0
 

Author Comment

by:APPIREDDY
ID: 23624750
thankyou rrz,kuladeep
i'm getting a syntax error at line 14
i don't understand what it is

An error occurred at line: 14 in the jsp file: /shop/shop-products.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens

can you help me
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 23624796
can you post the full stacktrace of the error.. while looking at your code above one thing that I can right away see is that you are declaring you resultset as "RS" and trying to use it as "Rs"...
0
 

Author Comment

by:APPIREDDY
ID: 23624927
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 15 in the jsp file: /shop/shop-products.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens


      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
      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)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.12
0
 

Author Comment

by:APPIREDDY
ID: 23624957
i have changed Rs to RS still the same
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 23625083
Interesting..

do you have any comments or something like that? normally the error above comes when there are unclosed comments tags and things like that..

Also is that the full code of your jsp thats posted above?

0
 

Author Comment

by:APPIREDDY
ID: 23625148
there is no comment in the code i'm  attaching the code again

<%@ page language="java" contentType="text/html"  errorPage="errorpage.jsp" %>
<%@ page import = "shop.*" %>
<html>
<head><title>Welcome to the shop </title></head>
<body>
<table width="385" border="0" cellspacing="0">
<tr><td colspan="4">More books from Mike McGrath:</td></tr>
<tr><td colspan="4" align="right">
<a href="<%= response.encodeURL("shop-basket.jsp")%>">
<img src="images\viewbasket.gif"></a></td></tr>
<tr>
<td><b>Ref</b></td><td><b>Title</b></td>
<td><b>Price</b></td><td></td></tr>
 
<% Class.forName("com.mysql.jdbc.Driver"); 
   java.sql.Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop","anu","kodanda");
   System.out.println("successful");
   java.sql.Statement stmt = connection.CreateStatement();
   java.sql.ResultSet RS = stmt.executeQuery("select * from items");
   
   int rowCounter=0;
   while(RS.next())
   {
	   String item_id = RS.getString("item_id");
	   String title = RS.getString("title");
	   String description = RS.getString("description");
	   String price = RS.getString("price");
	   rowCounter++;
	   String bg =(rowCounter % 2 !=0)?"#C0C0C0":"FFFFFF";
>%
	   <tr bgcolor="<%= bg %>">
	   <td><%= item_id %></td>
	   <td><b><%= title %><b><br/><%=description %></td>
	   <td>£<%=price %></td>
	   <td>
	   <a href="<%= response.encodeUrl("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price)%>">
	   <img src ="images\addtobasket.gif"><a></td>
	   </tr>
<%  }RS.close(); connection.close();%>
</table>
<jsp:useBean id="basket" class="shop.ShoppingBasket" scope="session"/>
<% String title = request.getParameter("title");
	   if(title!=null)
	   {
		   String item_id = request.getParameter("item_id");
		   double price = Double.parseDouble(request.getParameter("price"));
		   Product item = new Product(item_id,title,price);
		   basket.addProduct(item);
	   }
%>
</body></html>

Open in new window

0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 1000 total points
ID: 23625285
sometimes its little silly items that kill it..:)

          String bg =(rowCounter % 2 !=0)?"#C0C0C0":"FFFFFF";
>%


needs to be

          String bg =(rowCounter % 2 !=0)?"#C0C0C0":"FFFFFF";
%>

Notice the location of the % sign
0
 
LVL 28

Assisted Solution

by:rrz
rrz earned 1000 total points
ID: 23627575
>         String bg =(rowCounter % 2 !=0)?"#C0C0C0":"FFFFFF";
That line should compile.  Just needs a little help.
String bg =(rowCounter % 2 !=0)?"#C0C0C0":"#FFFFFF";
It is the next line after that one that looks bad to me.
29:>%
shouldn't that be  
29:%>

>An error occurred at line: 15 in the jsp file: /shop/shop-products.jsp
Which is line 15 anyway?  
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 23631603
I believe RRZ also helped in this problem, so he also needs to share the points with me.
0
 
LVL 28

Expert Comment

by:rrz
ID: 23634593
thanks kuldeep, I appreciate that
0
 
LVL 28

Expert Comment

by:rrz
ID: 23654296
I requested the attention of an adviser.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question