eclipse 如何创建一个 java servlet 程序并使用 XAMPP Tomcat 运行它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12654625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I create a java servlet program and run it using XAMPP Tomcat?
提问by six.strings.and.a.bit
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.)
我刚刚学习了 Java 中的 Servlet,但现在,我不知道如何运行 Java Servlet 程序。我正在使用 Eclipse SDK,并且已经添加servlet.jar
到库中。我安装了最新版本的 XAMPP,如下图所示,Tomcat 已经列在 Module 下(根据我在 Google 上的研究,我们将 Tomcat 用于 JSP 和 Servlet。)
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?
下面是我从这个网站得到的一个例子。您能否通过列举有关如何执行此操作的分步过程来帮助我使用 XAMPP Tomcat 运行此程序?
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.
非常感谢。
采纳答案by Abubakkar
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
为什么要为 servlet 使用 XAMPP。Tomcat 包含运行 servlet 所需的各种 jar 库。确保按照 java wep 应用程序的要求,将所有 jar 放置在正确的目录结构中。您还需要将类路径设置为该 jar 文件
回答by sivasai
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:
我还使用 xampp 来运行 servlet 和 jspi。
我在本地磁盘中安装了我的 xampp。
因此,为了运行 servlet,我提供了以下路径:
D:\xampp\Tomcat\lib\servlet-api.jar
in classpath in environment variables and similarly to run jsp
在环境变量中的类路径中,类似于运行 jsp
D:\xampp\Tomcat\lib\jsp-api.jar
So I think it is sufficient. Try it.
所以我觉得已经足够了。尝试一下。