I'm new to java servlets ...I installed Sun java SDK which acts as an server for running servlets.I spents many hours first just to compile servlets and generate the class files but now I don't have any idea how to run servlets on SDK. I tried a lot on Apache tomcat, Servletexec and now SDK but ended up wasting a number of hours and no result. I'm dying to see a page running my applet http://localhost/servlet/HelloServlet

Please please do help :'( :'(

Dani AI

Generated

Quick clarification for others who land here: the Java SE JDK is for building Java code — it is not itself a servlet container. Servlets must run inside a container such as Tomcat, Jetty or GlassFish. was right to separate applets (client-side) from servlets (server-side), and was right to point to container documentation. Below is a compact, practical checklist and the most common causes when http://localhost/servlet/HelloServlet doesn’t work.

Minimal checklist to go from source to browser:

  1. Compile against the servlet API (use the container’s servlet-api.jar):

    javac -cp /path/to/tomcat/lib/servlet-api.jar -d WEB-INF/classes src/com/example/HelloServlet.java
  2. Use the standard webapp layout (exploded or WAR):

    myapp/
    WEB-INF/
     web.xml
     classes/com/example/HelloServlet.class
     lib/  (third-party jars)
  3. Map the servlet (web.xml) or use annotation (Servlet 3.0+):

    <servlet>
    <servlet-name>Hello</servlet-name>
    <servlet-class>com.example.HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Hello</servlet-name>
    <url-pattern>/hello</url-pattern>
    </servlet-mapping>

or

@WebServlet("/hello")
public class HelloServlet extends HttpServlet { ... }
  1. Deploy the WAR or copy the folder into Tomcat’s webapps/, start Tomcat and visit:
    http://localhost:8080/myapp/hello

Troubleshooting tips (most common pitfalls):

  • Check container logs (catalina.out) for ClassNotFound or deployment errors.
  • Don’t bundle servlet-api.jar inside WEB-INF/lib — it causes classloader conflicts.
  • Ensure your compiled classes match their package path under WEB-INF/classes.
  • Verify the container port (Tomcat defaults to 8080) and that the old invoker URL (/servlet/...) is typically disabled for security; map your servlet explicitly.
  • Confirm Java bytecode version is compatible with the server JVM.

Good to see got Tomcat working — for repeatable builds, use an IDE (Eclipse/IntelliJ) or Maven/Gradle to produce a WAR and inspect logs when things still fail.

Recommended Answers

All 3 Replies

Tomcat comes with tutorials. So does the JEE SDK.

There's also tons of tutorials (of highly variable quality) scattered around the web.
And every decent bookstore has a shelf of books to choose from.

I got the the things working at last on tomcat
Thnx for ur humble replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.