File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes make servlet the default Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "make servlet the default "welcome" file for the web app" Watch "make servlet the default "welcome" file for the web app" New topic

make servlet the default "welcome" file for the web app

Trunali Grissom

Joined: Nov 10, 2003
Posts: 3
I am creating an application in which I would want my first page(viewable to the user) to have a list that was generated using a DB call.
Currently, since I am using MVC architechture, so this logic( DB call ) is hidden in a servlet called, "". Since the logic should be hidden, I am implementing a redundant step. In my index.jsp, which is my current default "<welcome file>", all I have is
<jsp:forward page="./"></jsp:forward> makes the DB call and stores the info in a vector which is set as an attribute to the request object. After this, welcome.jave forwards to a jsp "home.jsp", which accesses the request attribute and builds up a list.
My question is : Is there a way of bypassing the index.jsp route? All that this page does is forward to If somehow I could make my webcontainer call "" when the users run the app, then I could do away with "index.jsp". Is there a way to make a servlet a "<welcome file>" ( as in web.xml ) of the application?
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 642
One confusion....
what do u mean by in
<jsp:forward page="./"></jsp:forward>?
well now coming back to your problem,I cudnt make taht work.
But i manage to do same thing with html,dont know wether it has any impact on perfomance still .....
just add this line in inde.html


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
please look at using web.xml within your context /WEB-INF directory to create a servlet mapping. If you create a mapping from / to your servlet then when they open that folder it will show your servlet.
unless you have a very strange setup then
<jsp:forward page="./"></jsp:forward>
shouldnt work. I'm presuming your doign something like page="servlet/blah"
also note you dont need the </jsp:forward> if you close the first tag in itself like this:
<jsp:forward page="servlet/blah" />

Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Trunali Grissom

Joined: Nov 10, 2003
Posts: 3
Thank you for your comments.
Praful, the is a servlet and forwarding to a servlet should work. It is working for my application. I dont need to use the html format as it works using the jsp tags.
I looked at your comments. I think I am not clear about what you are saying. Are you saying that by somehow mapping the servlet "" and set it's url pattern to "/context root/ " will make it the default to the web application?
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
what i'm saying is edit your web.xml to have this in it:

if you don't know what web.xml is you need to go read some servlet tutorials / introductions
Marty Hall
Ranch Hand

Joined: Jan 02, 2003
Posts: 111
A couple of quick comments:
  • I assume you don't really mean "" in your jsp:forward call, but instead mean "registered-URL-of-the-Welcome-servlet".
  • No, you can not use the address of a servlet in the web.xml welcome-file-list element, at least not until JSP 2.0. That entry specifies physical files in the directory, not general URL patterns (that is why it is called welcome-file-list instead of welcome-pattern-list or some such, BTW).
  • However, the servlet-mapping element lets you specify arbitrary URL patterns that should be answered by servlets, so you can easily use this to skip the index.jsp step.
  • Very minor detail, but you can do <jsp:forward page="blah"/> instead of <jsp:forward page="blah"></jsp:forward>, if you want.

  • Cheers-
    - Marty
    [ November 11, 2003: Message edited by: Marty Hall ]

    Java training and consulting
    I agree. Here's the link:
    subject: make servlet the default "welcome" file for the web app
    jQuery in Action, 3rd edition