I'm using Eclipse and wanted to run a simple servlet. I made a project on the workspace as you can see on the attached image. And got a code on WEB-INF/src on temp project
How do I run the FirstServlet? Can't seem to find an answer. All I found on the net was putting my class to ROOT/WEB-INF/classes on Tomcat's installed folder. Any articles or links for this stuff is very well accepted and thanked.
Thank you so much.
Last edited by nebulom; May 25th, 2005 at 04:41 AM.
I haven't had the chance to run any servlets, only Bean's which i place in this directory C:\Jakarta\jakarta-tomcat-5.0.28\webapps\ora\WEB-INF\classes\com
and .jsp pages that are in the following C:\Jakarta\jakarta-tomcat-5.0.28\webapps\ora. I think both are executed a little differently though.
The thing is I want to test it not on my Tomcat's installed directory/webapps/ROOT/WEB-INF/classes but on my Eclipse's workspace/project/WEB-INF/classes. It's ok though if I just copy the class on Tomcat's installed directory/webapps/ROOT/WEB-INF/classes. But is there any work around with running it not on Tomcat's installed dir? Thanks, D
To be honest i really don't know. I mainly write my code in EditPlus and if it's jsp code, when im finished, i just drop it in the proper Jakarta directories and execute via my browser.
Dosen't Eclipse their own forums? Maybe you could post over there and see if you get an answer. I know im always over at Sun's forum's or MySql's when i need to get specific help.
Sorry for the late reply D, I can't seem to find Eclipse forum. I just registered to Suns' forum but quite not comfortable on posting there, so I just decided finding it myself and hopefully if I can, I'll post it here.
Ok, I just found out it has to do with the web.xml in our project or what they call the Deployment Descriptor. Also to be set on server.xml as the Contextpath to our project. Sample is like this... First structure our project like this
VB Code:
C:\projects\java\test
+ WEB-INF
+ src
+ classes
+ lib
+ web.xml
Though lib is optional and might not be putting our code on src folder but this is just a test, so we do it that way. In the src folder we might have a class that extends HttpServlet that might look like this
Just a test so what matters for now is just the name of the servlet. Compiling this with javac -d ../classes webtest.java will have a webtest.class under the classes folder. Now, we have to define the descriptor of our project. In our web.xml we might have something like this
VB Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>webtest</servlet-name>
<servlet-class>webtest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webtest</servlet-name>
<url-pattern>/webtest</url-pattern>
</servlet-mapping>
</web-app>
That is to inform Tomcat we have a servlet named webtest and we want to access it using the url pattern (/webtest). The question now is how the heck does Tomcat know where is that thing. In our %CATALINA_HOME%/conf folder, we have a server.xml that is needed in Tomcat's configuration. We have to add something... In this case we might be adding it on the last line under the <Host> tag
The . . . just above the <Context path tag implies that there's something up and that's just the default config tags provided by Tomcat.
By then we will be able to access the servlet like this http://localhost:8080/webtest/webtest. The dark orange signifies the project and the red for the servlet. This btw, assumes we have our port listening to 8080 (though here we have 8888, recommended by our seniors, hehehe, can't do anything but to follow). Running this will have a header(1) labeled servlet test.
Last edited by nebulom; Jul 1st, 2005 at 04:54 AM.