Reputation: 527
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.)
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.
Upvotes: 2
Views: 15719
Reputation: 21
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.
Upvotes: 1
Reputation: 15644
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
Upvotes: 0