Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet in welcome-file-list

 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Is it possible to invoke a servlet as welcome-file .
I tried placing servlet in DD , in many ways:
<welcome-file-list>
<welcome-file>Servlet</welcome-file>
</welcome-file-list>
but Tomcat wont recongnize.
So , CAN we use servlet as welcome file or not?

------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
satish kolli
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you can give your URL-PATTERN Which you gave in SERVLET-MAPPING.
For ex: If /servletToJsp is the url-pattern in my servlet mapping to my actual servlet
<welcome-file-list>
<welcome-file>/servletToJsp</welcome-file>
</welcome-file-list>
Thanks!
Satish Kolli, SCJP2
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx satish !
I tried ur solution , but it do not work , at least not with Tomcat4.0.1 . Which web-container u r using ?
Any other idea? anyone
------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
Tim Duncan
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it does say <welcome-file>, so I guess it's not surprising.
You could use HTML/Javascript trickery to achieve your aim. Your welcome file would be a minimal file like the following, which redirects to the servlet URL (the refresh is there in case Javascript is disabled).

<HTML>
<HEAD>
<META HTTP-EQUIV="refresh" CONTENT="5;
URL="http://localhost:8080/servlet/Test">
</HEAD>
<BODY>
<SCRIPT>
window.location.href =
"http://localhost:8080/servlet/Test/";
</SCRIPT>
</BODY>
</HTML>

[This message has been edited by Tim Duncan (edited November 02, 2001).]
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankx Tim
Nice tweak , and it works very fine .
But so is it final now that "we can NOT directly place servlet as a welcome-file " , right?

------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
Stefan Stefansson
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I simply use a servlet mapping to / for that.
Here's a sample web.xml that defines one servlet and maps that to the root of the context:
 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Servlet 2.4 spec allows a servlet as a welcome file.
http://www.onjava.com/pub/a/onjava/2004/02/11/jspcookbook.html
If you are using Tomcat 5.x, you can take advantage of this feature.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic