URL Syntax Used in web.xml

hw3281
hw3281 used Ask the Experts™
on
Hi. I am confused with the syntax used to specify a link in the configuration file (web.xml) of Tomcat JSP/Servlet container.  I attach herewith a portion of my web.xml.

=============================================
    <servlet>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <servlet-class>org.apache.jsp.index_jsp</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>org.apache.jsp.index_jsp</servlet-name>
        <url-pattern>/index.jsp</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>tomcat.gif</welcome-file>
    </welcome-file-list>
=============================================

I tried subtitute the /index.jsp with index.jsp (without the forward slash) for my <url-pattern> element. It just did not work. So, my question is, is there any rule to follow when specifying a link in the web.xml? Thanks in advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mick BarryJava Developer
Top Expert 2010

Commented:

Author

Commented:
Hi objects. I understand the mechanism in mapping a url parttern to a servlet. I just wonder why is it sometimes a forward slash is needed and sometimes not. For example, you don't need to put the forward slash for your welcome file, right? In my web.xml attached, it is the same whether it is tomcat.gif or /tomcat.gif (with slash). Thanks for your help.
Mick BarryJava Developer
Top Expert 2010

Commented:
> you don't need to put the forward slash for your welcome file, right?

correct, it just expects a filename *not* a url pattern

Author

Commented:
I think I get what you mean. So, you are telling that anything to do with url pattern is to start with a forward slash, is it?
Java Developer
Top Expert 2010
Commented:
yes, unless it's a *.extension. Otherwise I can't think of anything it would match (as paths start with a slash)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial