|
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 |
- Re: Simplest Possible Servlet R Felipe
- Re: Simplest Possible Servlet Richard Draucker
- Re: Simplest Possible Servlet R Felipe
- Re: Simplest Possible Servlet R Felipe
- Re: Simplest Possible Servlet R Felipe
