How do I create a java servlet program and run it using XAMPP Tomcat?

14,540

Solution 1

Why do you want to use XAMPP for servlet. Tomcat is contains variuos jar libraries necessary to run servlets. Make sure you have all that jars placed in proper directory structure as required for java wep apps. Also you need to set classpath to that jar files

Solution 2

I am also using xampp to run servlets and jspi.
I'installed my xampp in localdisk.
So, to run servlets I gave the following path:

D:\xampp\Tomcat\lib\servlet-api.jar  

in classpath in environment variables and similarly to run jsp

D:\xampp\Tomcat\lib\jsp-api.jar

So I think it is sufficient. Try it.

Share:
14,540
six.strings.and.a.bit
Author by

six.strings.and.a.bit

Computer Science student

Updated on June 04, 2022

Comments

  • six.strings.and.a.bit
    six.strings.and.a.bit over 1 year

    I just learned about Servlet in Java but right now, I do not know how to run Java Servlet programs. I am using Eclipse SDK and I already added servlet.jar in the libraries. I installed the latest version of XAMPP and as you can see in the image below, Tomcat is already listed under Module (based on what I researched on Google, we use Tomcat for JSP's and Servlets.)

    XAMPP Control Panel

    Below is an example I got from this site. Can you help me run this program using XAMPP Tomcat by enumerating the step-by-step process on how to do it?

    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 {
        PrintWriter out = response.getWriter();
        out.println("Hello World");
      }
    }
    

    Thank you very much.

  • six.strings.and.a.bit
    six.strings.and.a.bit about 11 years
    Where can I download those jar libraries?
  • Abubakkar
    Abubakkar about 11 years
    Dowload Apache Tomcat 6 or 7 from their website it will have all important jars tomcat.apache.org/download-70.cgi Installation and setup guide - tomcat.apache.org/tomcat-7.0-doc