Sunday, May 18, 2008

Eclipse + Servlet +Tomcat

For Tomcat version 6.0 and Eclipse version 3.3.0

You have to manually import context.xml from location
C:\Tomcat-6.0\conf\
to
MyWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf
and then changes to
Context reloadable="true"
and
privileged="true"

Now how to run servlets on Eclipse:

1- New "Dynamic web Project"
2- new -> Target run time -> choose tomcat server and its main folder as the source path.
3- R-click on the project -> new ->servlet (no need to have package name)
4- R-click on the servelt Java file and Run-as server

For the servlet to work the class file has to be in
/tomcat/webapps/project/web-inf/classes

and the HTML file (
with FORM METHOD=GET ACTION="Hello" , where Hello is the servlet name)can be in

/tomcat/webapps/project/

You can have multiple servlets defined inside web.xml, each one will be inside the servet tag.



No comments: