wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Servlet code problem....from HFSJ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Servlet code problem....from HFSJ" Watch "Servlet code problem....from HFSJ" New topic
Author

Servlet code problem....from HFSJ

Mannu hak
Ranch Hand

Joined: Apr 26, 2005
Posts: 50
I am having problem with the servlet code in HFSJ.

Here is the HTML code -
<html><body>
<h1 align="center"> Beer Selection Page </h1>
<form method = "POST"
action = "SelectBeer.do">
Select Beer Characterstics<p>
Color:
<select name="color" size="1">
<option>light
<option>amber
<option>brown
<option>dark
</select>
<br><br>
<center>
<input type = "SUBMIT">
</center>
</form></body></html>
*************************
Here is the XML-
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>Ch3 Beer</servlet-name>
<servlet-class>com.example.web.BeerSelect</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Ch3 Beer</servlet-name>
<url-pattern>/SelectBeer.do</url-pattern>
</servlet-mapping>

</web-app>
******************
Here is the 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);
}
}
**************

Now when i use http://localhost:8080/Beer-v1/form.html and click on the submit button to invoke the servlet, then instead of invoking the servlet it give the following exception.

exception

javax.servlet.ServletException: Wrapper cannot find servlet class com.example.web.BeerSelect or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Unknown Source)

*********

Now i have checked that BeerSelect class is present in Tomcat 5.0\webapps\Beer-v1\WEB-INF\classes\com\examples\web, so i dont know what to do next...

Please Help...


SCJP 1.4, SCWCD 1.4, SCBCD <br />IBM 285
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
Hi,

After you compiled the servlet and copied it into the Tomcat 5.0\webapps\Beer-v1\WEB-INF\classes\com\examples\web directory and saved the web.xml file. did you restart Tomcat?

if not go to Start->Settings->Control Panel->Administrative Tools->Services Highlight Apache Tomcat (2nd entry in my list) and go to Action->restart

once it has restarted give it 5 seconds and then in a new browser window type in the url to the form.html page again and try clicking the button. It may be that Tomcat just has not loaded the servlet.

Mat
Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
Hi,

Plz ensure that u've placed the .class file in the correct location.If you are following the same package structure as given in the code then see to that BeerSelect.class file is placed in WEB-INF/classes/com/example/web.
It should work if u assert the above case.

Hope it helps!!

Regards,
Priya.
Mannu hak
Ranch Hand

Joined: Apr 26, 2005
Posts: 50
Hi Mat and Priya,

Thanks for replying...But i have already looked into those pitfalls...

Anyway, I am in the office now, will give it a try after going home in the evening and then might come back for help.
Mannu hak
Ranch Hand

Joined: Apr 26, 2005
Posts: 50
ok, guys I'm back.

Its still not working for me...
any suggestions....
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
Hi,

wow more ideas , it works here for me so I guess that is is either something is in the wrong spot, or there is an error somewhere, cos I have done something different without realising it.

Is there an error in the logs that will shed some light on things. The easiest way is to stop the tomcat service. open a explorer window in {tomcat installation directory}\logs and delete all the files. then restart tomcat and see if there are any errors reported in the log files, they would probably be in the stdout.log file. It is worth noting that the stdout.log file takes, depending on the speed of your pc, 10 seconds or so to be fully populated after restarting Tomcat.

The reason I suggest that you stop Tomcat and delete the logs is that sometimes old errors can confuse the situation more, so best to start with a clean slate.

Mat
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
hi mannu,

i got the same problem as you as i first time click on "submit" button. And it gave me exceptions page as you mentioned..but then i check my path and tomcat service...

i stop tomcat, and restart it in the Control Panel path that you taught me one...remember??? right-click and select "restart".
------------------------------------------------------------
here is what under Tomcat directory
-----------------------------------
my BeerSelect class = C:\Tomcat_5.5\webapps\Beer-v1\WEB-INF\classes\com\example\web

my web.xml = C:\Tomcat_5.5\webapps\Beer-v1\WEB-INF

my form.html = C:\Tomcat_5.5\webapps\Beer-v1

----------------------------------------------
here is what under development directory
------------------------------------------
my form.html = C:\MyProjects\beerV1\web

my web.xml = C:\MyProjects\beerV1\etc

my BeerSelect java file = C:\MyProjects\beerV1\src\com\example\web

my BeerSelect class file = C:\MyProjects\beerV1\classes\com\example\web

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

i guess this is it ....i follow exactly what HFSJ said....esp the page 72 and 73. i look for that 2 pages for so many times....haha...

well...hope you can "heal" the problem you facing...okay.....all the best...


From NickyEng
Diploma in Computer Studies
SCJP 1.4
SCWCD 1.4
Formula 1 app by Maxis (Playbook)
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
i have a question. i dont wanna open a new thread, so i just continue with this thread, do you mind, Mannu?


when i compile the "BeerExpert.java", every path was correct, but after compile it, it give me something like this :



what is that means??? anyone know???

[ September 13, 2005: Message edited by: Nicky Eng ]
[ September 13, 2005: Message edited by: Nicky Eng ]
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
Hi Nicky,

from memory you have Java 1.5 installed, if that is correct then I found this on the sun java forums site - it should explain things far better than I could.

these messages occur when you are using classes that support the new J2SE 1.5 feature - generics. You get them when you do not explicitly specify the type of the collection's content.

For example:

List l = new ArrayList();
list.add("String");
list.add(55);

If you want to have a collection of a single data type you can get rid of the messages by:

List<String> l = new ArrayList<String>();
list.add("String");

If you need to put multiple data types into once collection, you do:

List<Object> l = new ArrayList<Object>();
list.add("String");
list.add(55);

If you add the -Xlint:unchecked parameter to the compiler, you get the specific details about the problem.


HTH

Mat
Mannu hak
Ranch Hand

Joined: Apr 26, 2005
Posts: 50
got it working guys...

can't belive i was doing such a stupid mistake...

I had wrongly named my example folder as examples

thanks guys..
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
Hi,

Well done - those sorts of problems are really really annoying when they happen. Well spotted.

Mat
Nicky Eng
Ranch Hand

Joined: Mar 26, 2005
Posts: 378
hi Mat, thanks for your explanation...now i understand...thanks alot.

by the way, i know there is a topic where a guy having problem when compiling "BeerSelect.java" (version 2), stated that :

import com.example.model.*; <---------------give me "package does not exits" error

BeerExpert.java
--------------------------------


BeerSelect.java
------------------

so i am facing the same problem...from yesterday until i try to check, fix...but no solution.....is it really classpath issue???

here is my classpath:

servlet-api.jar = C:\Tomcat_5.5\common\lib

BeerSelect.java = C:\MyProjects\beerV1\src\com\example\web

BeerExpert.java = C:\MyProjects\beerV1\src\com\example\model

when i compile:
-------------------------------------
C:\MyProjects\beerV1> javac -classpath /Tomcat_5.5/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java
-------------------------------------

and it give me "package does not exist" as above mentioned. haiz...where is my classpath wrong???
 
 
subject: Servlet code problem....from HFSJ