Thanks for replying. Here's an update on my progress:
On the examples folder (c:\tomcat\webapps\examples\WEB-INF\classes) where
Tomcat examples are working but mine won't. I tried renaming my
"HelloWorld" to Tomcat's "HelloWorldExample" and it works!! So somewhere it
is configured to look for "specific" file names. I checked the examples
folder (same as above) and I found 3 "properties" file.
LocalStrings.properties, LocalString_en.properties, and
LocalString_es.properties. I couldn't find any reference where a filename
may have been hard-coded. But I know that this is what the "ResourceBundle"
class is using. I think it's for different language support. "en" for
english and "es" for spanish. Anyway, I still don't know why my own
HelloWorld wouldn't run. At this point I don't care because it's just the
example and there's a configuration there somewhere for it I'm sure.
Now to my real servlet folder (c:\tomcat\webapps\ROOT\WEB-INF\classes).
The same HelloWorld program only works if I put it in a package. So I
create a folder under \classes\ called "mypackage" and add the line "package
mypackage;" to my java file. If I don't I get the error:
Location: /servlet/helloworld
Internal Servlet Error:
java.lang.IllegalAccessException: helloworld
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:237)
at
org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:268)
at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
at org.apache.tomcat.core.Handler.service(Handler.java:254)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
at java.lang.Thread.run(Thread.java:484)
On the same folder (under \classes\) there is a java servlet file called
SnoopServlet and this one works. So why is it that I need to have my
servlets in a package? Is this how Tomcat is suppose to work out-of-box
without configuration? It doesn't make sense.
-Ray
----- Original Message -----
From: "Richard Draucker" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 15, 2001 9:49 PM
Subject: Re: Simplest Possible Servlet
> Couple of things...
> First, yes, Jrun and Tomcat are very different. Jrun does
> not fully conform to the J2EE webapp spec. It allows
> servlets to be run from all over the place and even has an
> old 'servlets' directory for backward compatibility.
> Tomcat requires that your directory structure look like:
> webapps/html/WEB-INF/classes
> ... where HTML pages go in whatever you name the 'html'
> directory and sevlets go in the /classes directory. You
> need not declare the servlets in the web.xml file if you
> access them via http://yoururl.com/servlets/myservlet
> syntax. But, if you want to use
> http://yoururl.com/helloworld
> the alias must be declared in the web.xml file in the
> WEB-INF directory.
> Since you reference the HelloWorldExample working 'in the
> same directory', I'm wondering if you maybe dropped a new
> HelloWorld servlet in the /classes directory under
> webapps/examples. If this is the case, Tomcat may not see
> it. I believe the examples directory exists only for
> reference and that the url
> http://youurl.com/examples/servlet/HelloWorldExample is
> actually reaching a servlet inside an examples.war file.
> Check your server.xml file and see if you have a context
> for webapps/examples.
> You may have better success creating a new J2EE compliant
> directory structure and dropping your servlet in there.
>
>
>
>
> On Wed, 16 May 2001, you wrote:
> > Sorry I didn't mention but the case is correct. Java file is called
> > HelloWorld.java, class file is called HelloWorld.class.
> >
> > -Ray
> >
> > ----- Original Message -----
> > From: "Richard Draucker" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, May 15, 2001 8:31 PM
> > Subject: Re: Simplest Possible Servlet
> >
> >
> > > Easy question of the day...
> > > as the trace says, wrong name: helloworld
> > > try HelloWorld instead.
> > > Yep, case sensitivity strikes again.
> > >
> > >
> > >
> > >
> > >
> > > On Tue, 15 May 2001, you wrote:
> > > >
> > > > Here is the simplest possible servlet from the Core Servlets book
from
> > Sun
> > > > by Marty Hall:
> > > >
> > > > import java.io.*;
> > > > import javax.servlet.*;
> > > > import javax.servlet.http.*;
> > > >
> > > > public class HelloWorld extends HttpServlet {
> > > > public void doGet(HttpServletRequest request,
HttpServletResponse
> > > > response)
> > > > throws ServletException, IOException {
> > > > response.setContentType("text/html");
> > > > PrintWriter out=response.getWriter();
> > > > out.println("Hello World");
> > > > }
> > > > }
> > > >
> > > >
> > > >
> > > > This code (above) runs perfectly on my JRun server. When I try it
on my
> > > > Tomcat I get an error 500 (see below):
> > > >
> > > > Internal Servlet Error:
> > > >
> > > > java.lang.NoClassDefFoundError: HelloWorld (wrong name: helloworld)
> > > > at java.lang.ClassLoader.defineClass0(Native Method)
> > > > at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
> > > > at
> > java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
> > > >
> > > > -----rest of error here.......
> > > >
> > > > You might be thinking I don't have the class file on the correct
> > directory
> > > > but another hello world example from Tomcat is working perfectly on
the
> > same
> > > > directory. Here is the code for the one that works.
> > > >
> > > > /* $Id: HelloWorldExample.java,v 1.2.4.1 2000/07/05 17:45:01 nacho
Exp $
> > > > *
> > > > */
> > > >
> > > > import java.io.*;
> > > > import java.text.*;
> > > > import java.util.*;
> > > > import javax.servlet.*;
> > > > import javax.servlet.http.*;
> > > >
> > > > /**
> > > > * The simplest possible servlet.
> > > > *
> > > > * @author James Duncan Davidson
> > > > */
> > > >
> > > > public class HelloWorldExample extends HttpServlet {
> > > >
> > > >
> > > > public void doGet(HttpServletRequest request,
> > > > HttpServletResponse response)
> > > > throws IOException, ServletException
> > > > {
> > > > ResourceBundle rb =
> > > >
> > ResourceBundle.getBundle("LocalStrings",request.getLocale());
> > > > response.setContentType("text/html");
> > > > PrintWriter out = response.getWriter();
> > > >
> > > > out.println("<html>");
> > > > out.println("<head>");
> > > >
> > > > String title = rb.getString("helloworld.title");
> > > >
> > > > out.println("<title>" + title + "</title>");
> > > > out.println("</head>");
> > > > out.println("<body bgcolor=\"white\">");
> > > > out.println("<body>");
> > > >
> > > > // note that all links are created to be relative. this
> > > > // ensures that we can move the web application that this
> > > > // servlet belongs to to a different place in the url
> > > > // tree and not have any harmful side effects.
> > > >
> > > > // XXX
> > > > // making these absolute till we work out the
> > > > // addition of a PathInfo issue
> > > >
> > > > out.println("<a href=\"/examples/servlets/helloworld.html\">");
> > > > out.println("<img src=\"/examples/images/code.gif\"
height=24 "
> > +
> > > > "width=24 align=right border=0 alt=\"view
> > code\"></a>");
> > > > out.println("<a href=\"/examples/servlets/index.html\">");
> > > > out.println("<img src=\"/examples/images/return.gif\"
height=24
> > " +
> > > > "width=24 align=right border=0
> > alt=\"return\"></a>");
> > > > out.println("<h1>" + title + "</h1>");
> > > > out.println("</body>");
> > > > out.println("</html>");
> > > > }
> > > > }
> > > >
> > > >
> > > > The only difference I can see is the ResourceBundle class. What is
it?
> > Is
> > > > that what's causing my problem? I tried putting it on my code and
I'm
> > > > getting the same error. Why does my first code works on JRun and
not
> > > > Tomcat? Are there differences between these 2 webservers as far as
> > these
> > > > HelloWorld programs are concerned. Thanks for your help.
> > > >
> > > > Struggling Newbie,
> > > >
> > > > -Ray
> > > >
> > > >
> > > >
> > >
> > > ----------------------------------------
> > > Content-Type: text/html; name="unnamed"
> > > Content-Transfer-Encoding: quoted-printable
> > > Content-Description:
> > > ----------------------------------------
> > >
> > > --
> > > Richard Draucker, [EMAIL PROTECTED]
> > > Protected-Data.Com www.protected-data.com
> > > Remote data support for web developers.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> --
> Richard Draucker, [EMAIL PROTECTED]
> Protected-Data.Com www.protected-data.com
> Remote data support for web developers.
>
>
>
>
>
>
>
>