File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Welcome file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Welcome file" Watch "Welcome file" New topic
Author

Welcome file

Tridib Samanta
Ranch Hand

Joined: Apr 28, 2004
Posts: 128
The following is an excerpt from DD of my "test" web application. Whenever I type, http://localhost:8080/test/xxx/ or http://localhost:8080/test/yyy/ I should always get the output from "Welcome Servlet" servlet. But I don't.

<servlet-mapping>
<servlet-name>Welcome Servlet</servlet-name>
<url-pattern>*.wc</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>welcome.wc</welcome-file>
</welcome-file-list>



Could you explain what's going wrong?


Thanks, Tridib
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Accordinlgy to HFSJ page 593, the following sequence is used to "find" the client's requested URL:

1) Container looks in the DD for a servlet mapping.
2) If a mapping cannot be found, the Container looks in the welcome-file-list, and starting from the first entry it founds, it tries to locate the specified welcome file within the directory received in the request.

In your case, the url doesn't match the servlet-mapping, and then there is no welcome.wc file in those directories.
[ March 27, 2007: Message edited by: Sergio Tridente ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Johan Pelgrim
Ranch Hand

Joined: Jul 07, 2003
Posts: 105

From the spec:

If a Web container receives a valid partial request, the Web container must
examine the welcome file list defined in the deployment descriptor. The welcome file list is an ordered list of partial URLs with no trailing or leading /. The Web server must append each welcome file in the order specified in the deployment descriptor to the partial request and check whether a static resource or servlet in theWAR is mapped to that request URI. TheWeb container must send the request to the first resource in the WAR that matches. The container may send the request to the welcome resource with a forward, a redirect, or a container specific mechanism that is indistinguishable from a direct request.


The only thing I can think of is when you request /test/xxx/ the container appends the welcome.wc from the welcome-file-list and first searches for a static resource with the name "welcome.wc" in the /test/xxx/ directory. If that does not exist (in this case) it looks for a servlet which is (statically?!) mapped to /test/xxx/welcome.wc, which in this case there is none... A lousy answer I know, but the *.wc url-pattern-welcome-file-list mapping simply does not seem to work. Anybody else have a good explanation?


Johan Pelgrim, The Netherlands
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

It seems that your web.xml is OK and the problem you are experiencing is due to a bug in (our version of) Tomcat. I found this link in Sun's developers network forum that explains how to workaround the bug. I just did what they suggest and it worked with your original web.xml.

I hope this helps.
Tridib Samanta
Ranch Hand

Joined: Apr 28, 2004
Posts: 128
Thanks much guys for your replies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Welcome file