[英]Access a Java Class with Tomcat
I created a java file and compiled it. 我创建了一个Java文件并对其进行了编译。 Now I have the directory WEB-INF/classes with HelloWorld.java and HelloWorld.class
现在我有了HelloWorld.java和HelloWorld.class目录WEB-INF / classes
Now the question is: How do I access it via Tomcat? 现在的问题是:如何通过Tomcat访问它? It is installed, the examples Tomcat coems with work.
它已安装,Tomcat的示例可以正常工作。 I don't know how to access the webdir(the name of the app I created in webapps)
我不知道如何访问webdir(我在webapps中创建的应用程序的名称)
I get the following error: 我收到以下错误:
type Status report 类型状态报告
message /webdir/ 消息/ webdir /
description The requested resource (/webdir) is not available. 说明所请求的资源(/ webdir)不可用。
Any program must have an entry point. 任何程序都必须具有入口点。 In the case of normal Java apps, it is a
public static void main(String[] args)
. 对于普通的Java应用程序,它是一个
public static void main(String[] args)
。 In the case of a Java web application, the entry points is typically the method doGet
of the the class HttpServlet
. 对于Java Web应用程序,入口点通常是
HttpServlet
类的doGet
方法。
So you must implement a class that extends this HttpServlet
class. 因此,您必须实现一个扩展此
HttpServlet
类的类。 Then, you need to setup a file webdit/WEB-INF/web.xml
where you will declare your Servlet, and make it visible through a given URL. 然后,您需要设置一个文件
webdit/WEB-INF/web.xml
,在其中声明您的Servlet,并使其通过给定的URL可见。
Check the examples that come with Tomcat, then google "Servlet", "web.xml" for more details. 查看Tomcat随附的示例,然后查看google“ Servlet”,“ web.xml”以获取更多详细信息。 Good luck.
祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.