how can I create a Tomcat 4.1 'index' servlet

M

Marc Twain

Hi - I went through a million websites and still can't find an answer
to the following problem on Tomcat 4.1

If I have an MVC app in a directory called 'myapp', and the controller
is a servlet, how can I have tomcat point at this 'index' servlet when
the user types: www.mysite.com/myapp/

I tried everything I could think off, the 'welcome file list' feature
in web.xml doesn't work for servlets, and a redirection from a default
Jsp file would be really dodgy.

Also, if anyone could let a poor soul know how to disable directory
browsing in tomcat, I would be most grateful.

TIA,

AJ
 
S

Sudsy

Marc said:
Hi - I went through a million websites and still can't find an answer
to the following problem on Tomcat 4.1

If I have an MVC app in a directory called 'myapp', and the controller
is a servlet, how can I have tomcat point at this 'index' servlet when
the user types: www.mysite.com/myapp/

I tried everything I could think off, the 'welcome file list' feature
in web.xml doesn't work for servlets, and a redirection from a default
Jsp file would be really dodgy.

Actually, that's precisely what's recommended in Programming Jakarta
Struts (ISBN: 0-596-00328-5). In your welcome-file-list you specify
something like welcome.jsp. Add an entry to your struts-config.xml
file like the following:

<global-forwards>
<forward name="welcome" path="main.do" />
<global-forwards>

Then the contents of welcome.jsp become:

<%@ taglib uri="logic" prefix="logic" %>
<html>
<body>
<logic:forward name="welcome" />
</body>
</html>

Of course this assumes you're using a URL pattern of *.do and that
you have an action defined with a path of "/main"...
 
C

Christophe Vanfleteren

Sudsy said:
Actually, that's precisely what's recommended in Programming Jakarta
Struts (ISBN: 0-596-00328-5). In your welcome-file-list you specify
something like welcome.jsp. Add an entry to your struts-config.xml
file like the following:

<global-forwards>
<forward name="welcome" path="main.do" />
<global-forwards>

Then the contents of welcome.jsp become:

<%@ taglib uri="logic" prefix="logic" %>
<html>
<body>
<logic:forward name="welcome" />
</body>
</html>

Of course this assumes you're using a URL pattern of *.do and that
you have an action defined with a path of "/main"...

Yes, that is what is recommended, but it still is basically just a workaround
for the fact that the <welcome-list> specification isn't flexible enough to
allow servlets (which is really stupid, since jsp's compile to servlets :).
They should have made that possible in the specification.

Using the redirection, the client has to make 2 requests where only one would
have been enough.
 
C

Chris Smith

Christophe said:
Yes, that is what is recommended, but it still is basically just a workaround
for the fact that the <welcome-list> specification isn't flexible enough to
allow servlets (which is really stupid, since jsp's compile to servlets :).
They should have made that possible in the specification.

I don't see how an implementation detail like JSPs compiling to servlets
makes anything more or less "stupid". The fact remains that the logic
for handling a directory request first requires checking to see if the a
welcome resource exists. It's tough to define "exists" for a servlet,
which may or may not decide to respond with 404 when it's run. Or
should a servlet be used for any welcome URI that it's mapped to, and if
so, what if it's mapped with a wildcard?
Using the redirection, the client has to make 2 requests where only one would
have been enough.

Actually, the "redirection" mentioned in this thread was actually a
forward from within the server, and the client sees nothing different.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
M

Marc Twain

Thanks for all the answers :)
I actually can answer my own question #2 (how to disable directory
browsing on Tomcat).

In server.xml (in catalina_home/conf), make sure the init param
'listings' is set to false for the default servlet.

AJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top