What would I need to change when I upgrade my servlet from JServ to Tomcat? -- 02.06.01
Created May 4, 2012
Ryan Breidenbach
Well, there isn't any reason that your servlet itself would have any specific code in it that would not allow it to be deployed on Tomcat. By this, I mean the code in the init
, service
, deGet
, etc. methods should be servlet-container independent.
That being said, all you should have to do it register the new servlet with Tomcat. This requires modifing two files, server.xml
and web.xml
.
The server.xml
file is where you will register your web application (the context in which your servlet will operate). This would look something like this:
<Server> <!-- other stuff here --> <ContextManager debug="0" workDir="workDir" > <!-- other stuff here --> <!-- your context --> <Context path="/myApp" docBase="webapps/myApp" debug="0" reloadable="true" / > </ContextManager> </Server>
The web.xml
file is where you will configure your web application. This includes configuring your servlet's alias and initial parameters. This would look something like:
<servlet> <servlet-name>myServlet</servlet-name> <servlet-class>com.mypackage.MyServlet</servlet-class> <init-param> <param-name>param1</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>myServler</servlet-name> <url-pattern>/useMyServlet</url-pattern> </servlet-mapping>
See the Tomcat Users Guide for more details.