Thursday, February 09, 2006

How to load resources in a servlet.


Resources like images and similar contents can be loaded by using
Fully qualify references to other resources from the context path.

img src="${pageContext.request.contextPath}/images/myImage.png}" alt="..." />

or for containers that don't support JSP 2.0:

img src="<%=request.getContextPath() + "/images/myImage.png"%> alt="..." />

Wednesday, February 08, 2006

Tomcat Administration

How to figure out the number of Servlets that are deployed as part of a given web application.

To go to HTML Manager app we go to configure the Tomcat-Home/config/tomcat-users.xml file, by adding

role rolename="manager"/
role rolename="admin"/

user username="admin" password="" roles="admin,manager"/

these elements. Once done with this we got to restart Tomcat and goto to default Tomcat login-page, with the following URL.

http://localhost:8080/

We will be able to see "Administration" at left corner of the page below the tiger image with links to
1. Status
2. Tomcat
Administration
3.
Tomcat Manager

Click the second link. You will get a browser pop-up dialogue box requesting UserName/Password. Enter
UserName as "admin" and no password.

Tomcat will show you the deployed servlets if you fire up the HTML Manager app and go to Server Status -> Complete Server Status you'll see a list of all the servlets deployed in each application along with some data for each of them.

Example:

Lets consider we got a Web Application called ServletMethods with 3 servlets in it. If we follow the above links you will see

-----------------------------------------------------------------------------------------
localhost/ServletMethods

default [ / ]

Processing time: 1 s Max time: 1219 ms Request count: 1 Error count: 0 Load time: 0 ms Classloading time: 0 ms

LoginServlet [ /login ]

Processing time: 0 s Max time: 547 ms Request count: 1 Error count: 0 Load time: 531 ms Classloading time: 531 ms

TestServ [ /ts ]

Processing time: 0 s Max time: 0 ms Request count: 0 Error count: 0 Load time: 0 ms Classloading time: 0 ms
jsp [ *.jsp , *.jspx ]

Processing time: 0 s Max time: 0 ms Request count: 0 Error count: 0 Load time: 15 ms Classloading time: 15 ms

MyServ [ /myser ]

Processing time: 0 s Max time: 0 ms Request count: 0 Error count: 0 Load time: 0 ms Classloading time: 0 ms

-----------------------------------------------------------------------------------------
Where LoginServlet, TestServ and MyServ are the servlet names and those inside brackets are the url-patterns to be used to reach the servlets.

You can also get other details like

1. Processing time
2. Max time
3. Request count
4. Error count
5. Load time
6. Classloading time