Setting up Tomcat port
Tomcat use 8080 port
instead of 80 port. User can easily change default port from tomcat.
Open c:/tomcat/config/server.xml folder in
tomcat installed and open server.xml file.
<! -- Define a non-SSL HTTP/1.1
Connector on port 8080 --> <Connector port="8080"
maxHttpHeaderSize="8192" maxThreads="150"
minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443"
acceptCount="100" connectionTimeout="20000"
disableUploadTimeout="true" /> <! -- Note: To disable connection
timeouts, set connectionTimeout value to 0 -->
In connector port change 8080 to 80, now save
this save and shutdown.bat tomcat and startup.bat tomcat. This time user needs
not to write 8080 port in http://localhost/
Servlet invoker
Servlet container of tomcat engine doesn’t
start automatically. WEB-INF deployment descriptor needs to tell servlet
engine, where your servlet and mapping of servlet. This is can be done without
any setting through servlet invoker. We just need to uncommented the code in
web.xml in config folder. Servlet invoker automatically load servlet in context
and map it.
Open c:/tomcat/config/web.xml and edit this
code as shown.
First uncommented invoker then servlet mapping
<!-- --> <!-- debug Debugging detail level for
messages logged --> <!-- by this servlet. [0] -->
<servlet>
<servlet-name>invoker</servlet-name> <servlet-class>
org.apache.catalina.servlets.InvokerServlet </servlet-class>
<init-param> <param-name>debug</param-name>
<param-value>0</param-value> </init-param>
<load-on-startup>2</load-on-startup> </servlet>
Also uncommented the servlet mapping
<!--
The mapping for the invoker servlet --> <servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern> </servlet-mapping>
<!-- The mapping for the JSP servlet -->
If you are using tomcat 6, need to define privileges for
context. In tomcat 5.5.x version no need to define privileges for context.
Tomcat 5.5.x takes automatically.
Privileges setting can be done in tomcat/conf/context.xml
file. Add this line
<Context reloadable="true"
privileged="true">
Deployment of jsp or servlet in Tomcat
All jsp and html page should be kept in C:\tomcat\webapps
and create your own folder or keep jsp file under default directory ROOT.
We would like to create new folder in webapps as home and keep all files in
this folder. In home folder create WEB-INF folder and inside this also create
two folder named as classes and lib and keep web.xml in WEB-INF. In classes’
folder, all servlets and JavaBeans should keep, Classes folder generally
contains class file and java file and when servlet engine starts, all java and
class file loaded in tomcat through bootstrap.jar which is in bin folder.
Create a first servlet example.
Deployment of Servlet
Servlet deployment needs to map in deployment
descriptor, if you have not enabled servlet invoker. Descriptor give us more
feature of deploying servlet with user defined URL context path.
All servlet needs to compile manually and
copy to WEB-INF/classes folder. Descriptor file is web.xml which
keeps all information of servlet and taglib’s. Suppose we are deploying TestServlet
servlet at default package. WEB-INF/classes/TestServlet.class; Make
a file
WEB-INF/web.xml
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/servlet/TestServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>