My Tomcat path D:\Program Files\Apache Software Foundation\Tomcat 5.0
My HtmlFile path E:\Programs\JSDK\DocRoot contains: FirstServlet.html
My ServletFile path E:\Programs\JSDK\Servlets contains: FirstServlet.java and FirstServlet.class
Now how to execute my servlet file?
This is my program
<HTML> <HEAD> <TITLE> Test to invoke a Servlet </TITLE> </HEAD> <BODY> <P> Invoking a Servlet from a Hyperlink </P> <P> <A Href="http://localhost:8080/servlet/FirstServlet"> Click here to invoke a Servlet </A> </P> </BODY> </HTML>
In order to execute your servlet you will have to create a web.xml file, which will contain the details about your FirstServlet.class and the URL used to invoke your servlet( in your case http://localhost:8080/servlet/FirstServlet ). Then you need to place your class files in the YourProject/WEB-INF/classes folder for the container to find them. Apart from that you will have to make sure your tomcat is running fine and class paths are set correctly. I suggest you either follow a book or check out the numerous sites on the web for the same. Check Marty Hall
I like your approach towards runing your first servlet. Sure it didn't work. Never mind, most of us had problem runing our first servlet. So you're on course. Let me take you through.
1. Organise the file structure. as follows (using Tomcat); under webapp; create a folder(call is serv - this is your app root dirctory) . 2. Create another, dir ( call it WEB-INF - a most, where your web.xml and classes and lib dir resides).
3. Compile your servlet class. (remember to add the servlet-api.jar in the classpath, if not the servlet class won't compile). put the compile servlet class into .../webapp/serv/web-INF/classes.
4. Create web.xml as follows.
<web-app> <servlet> <servlet-name>any name for servlet</servlet-name> <servlet-class>fully qualify name of servlet class (without class extention) </servlet-class> </servlet> <servlet-mapping> <servlet-name>same as above</servlet-name> <url-pattern>/serv.do</url-pattern> </servlet-mapping> </web-app>
5. Restart the web container. the hit the page using the name specified in <url-pattern>
Hope this clears some of the curious part of your first servlet.
SCJP, SCJA, SCWCD( in .....)
SCJA(Beta) SCJP 1.4 SCWCD 1.4 SCBCD 1.3 SCBCD 5.0 beta <br />The more practice we get, the better we are at the exams and in life in general. Pls join me at My DEN.
Joined: Oct 06, 2005
Now i'm able to run servlets!
I Thank again Mr.Abdulla Mamuwala and Mr.mi Mohammed