I created a java file 开发者_如何学JAVAand compiled it. Now I have the directory WEB-INF/classes with HelloWorld.java and HelloWorld.class
Now the question is: How do I access it via Tomcat? It is installed, the examples Tomcat coems with work. I don't know how to access the webdir(the name of the app I created in webapps)
I get the following error:
type Status report
message /webdir/
description The requested resource (/webdir) is not available.
Any program must have an entry point. In the case of normal Java apps, it is a 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
.
So you must implement a class that extends this HttpServlet
class. 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.
Check the examples that come with Tomcat, then google "Servlet", "web.xml" for more details. Good luck.
精彩评论