This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper cannot find servlet class

 
surbhi tugnawat
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!!

I am new to servlets. I am trying to run an example from head first servlets(page 81). I have copied BeerSelect.class froma different location. Rest all is same as it says in the book.

Errors I am getting are

javax.servlet.ServletException: Wrapper cannot find servlet class com.example.web.BeerSelect or a class it depends on


java.lang.ClassNotFoundException: com.example.web.BeerSelect



Please help!!

Surbhi
 
surbhi tugnawat
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I Start Tomcat by clicking start button on the Apache tomcat property window. Is it the right way of starting it???
http://localhost:8080 runs fine.

As I mentioned earlier I am having difficulties running the example in chapter 3 . I have my exapmle(Beer) in c:Tomcat/webapps/Beer

There I have a WEB-INF folder which has web.xml and classes folder and BeerSelect.class is in com.example.web.

When I run Tomcat I can open the form.html. This form instead of "Submit" button displays "Submit query"( Dont know why)
and when I pick the color from drop down and hit Submit query button.. i get Http Status 500 and above mentioned erros.

So thats my problem.
HELP!!!
Surbhi
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There I have a WEB-INF folder which has web.xml and classes folder and BeerSelect.class is in com.example.web

You mean you have BeerSelect.class in com/example/web don't you.

Don't worry about the 'Submit Query' thing, it's a HTML problem and not related to your issue. We can fix that later.
 
Manzar Zaidi
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by surbhi tugnawat:
[QB]There I have a WEB-INF folder which has web.xml and classes folder and BeerSelect.class is in com.example.web.


Just wanted to ensure that it is down the three folder hierarchy com, example and web and not a single folder names com.eaxmple.web !

Also, the class should have the matching package declaration in the code..so do you have a package com.example.web; in the source code ?
 
Manzar Zaidi
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by surbhi tugnawat:
[QB]There I have a WEB-INF folder which has web.xml and classes folder and BeerSelect.class is in com.example.web.


Just wanted to ensure that it is down the three folder hierarchy com, example and web and not a single folder names com.eaxmple.web !

Also, the class should have the matching package declaration in the code..so do you have a package com.example.web; in the source code ?
 
surbhi tugnawat
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes BeerSelect.class is in WEB-INF/classes/com/example/web...and I also have the package statement in it.
 
Manzar Zaidi
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by surbhi tugnawat:
javax.servlet.ServletException: Wrapper cannot find servlet class com.example.web.BeerSelect or a class it depends on


or a class it depends on
When you have the package set up properly and mapped correctly, it time we have to get into the code. Could you pleae paste the servlet code ?
And ... or a class it depends on..Please ensure that you have all the required libraries in the web-inf/lib folder.

The "Submit query" is the default message that shows up on submit button if you dont give it a name, so maybe your name element is missing or spelt wrong.
 
surbhi tugnawat
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Here is my Servlet code

package com.example.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class BeerSelect extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException{

response.setContentType("text.html");
PrintWriter out =response.getWriter();
out.println("Beer selection advice <br>");
String c=request.getParameter("color");
out.println("<br> Got beer color " + c);

}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic