Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Apache Tomcat 4.1.x: how to get front page without redirect like slashdot.org

Reply
Thread Tools

Apache Tomcat 4.1.x: how to get front page without redirect like slashdot.org

 
 
Alex Martinoff
Guest
Posts: n/a
 
      09-06-2003
Hello all,

Suppose I'm running slashdot.org except coded with Java instead of
Perl. I want the main page served by a servlet named index but without
any redirects. So when the user types

http://slashdot.org/

into their browser and goes there they won't be redirected to
http://slashdot.org/index. The real slashdot.org doesn't automatically
redirect you to index.pl. You just see http://slashdot.org/ in your
location bar. So, I tried to set this up with Tomcat and have only
found a partial-solution that isn't completely satisfactory.

My application's web.xml contains

<!-- ... -->
<servlet-mapping>
<servlet-name>index</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>article</servlet-name>
<url-pattern>/article</url-pattern>
</servlet-mapping>
<!-- ... -->

Then, I edited the site-wide web.xml in conf/ so that the default
servlet is no longer mapped to "/" but instead to the various types my
site uses like:
<!-- ... -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<!-- ... -->

If I don't do that then my images and css will no longer load. I
thought just simply making the change I made to my application's
web.xml would be sufficient, but apparently the meaning of
servlet-mapping to "/" isn't the intuitive thing of just mapping
requests for "/" to index and nothing else; it maps all other request
URIs not given servlet-mappings in those 2 web.xml files to the index
servlet instead of to the default servlet. That's what servlet-mapping
to something broader like "/*" or "/**/*" or something should do;
mapping to just "/" shouldn't give the effect it does. So if I do
http://localhost:8080/foo then I'll get the index servlet unless
foo=article or blah.gif, etc. I'd rather get a NOT FOUND message for
random URIs.

I suppose editing org.apache.catalina.servlets.DefaultServlet is a
possibilty, but there HAS to be a better approach! For example, can I
set up a default servlet that checks if the request is for "/" and if
it is then pass the request and response to the doGet (or doPost, as
the case may be) index serlet method? (If it's not for "/" then pass
the request and response to the usual DefaultServlet method.)

This is frustrating! Any and all replies really appreciated. Thanks a
bunch!
 
Reply With Quote
 
 
 
 
Kees de Kooter
Guest
Posts: n/a
 
      09-06-2003
(Alex Martinoff) wrote in
news: om:

> Hello all,
>
> Suppose I'm running slashdot.org except coded with Java instead of
> Perl. I want the main page served by a servlet named index but without
> any redirects. So when the user types
>
> http://slashdot.org/
>
> into their browser and goes there they won't be redirected to
> http://slashdot.org/index. The real slashdot.org doesn't automatically
> redirect you to index.pl. You just see http://slashdot.org/ in your
> location bar. So, I tried to set this up with Tomcat and have only
> found a partial-solution that isn't completely satisfactory.
>
> My application's web.xml contains
>
> <!-- ... -->
> <servlet-mapping>
> <servlet-name>index</servlet-name>
> <url-pattern>/</url-pattern>
> </servlet-mapping>
>
> <servlet-mapping>
> <servlet-name>article</servlet-name>
> <url-pattern>/article</url-pattern>
> </servlet-mapping>
> <!-- ... -->
>
> Then, I edited the site-wide web.xml in conf/ so that the default
> servlet is no longer mapped to "/" but instead to the various types my
> site uses like:
> <!-- ... -->
> <servlet-mapping>
> <servlet-name>default</servlet-name>
> <url-pattern>*.gif</url-pattern>
> </servlet-mapping>
>
> <servlet-mapping>
> <servlet-name>default</servlet-name>
> <url-pattern>*.css</url-pattern>
> </servlet-mapping>
> <!-- ... -->
>
> If I don't do that then my images and css will no longer load. I
> thought just simply making the change I made to my application's
> web.xml would be sufficient, but apparently the meaning of
> servlet-mapping to "/" isn't the intuitive thing of just mapping
> requests for "/" to index and nothing else; it maps all other request
> URIs not given servlet-mappings in those 2 web.xml files to the index
> servlet instead of to the default servlet. That's what servlet-mapping
> to something broader like "/*" or "/**/*" or something should do;
> mapping to just "/" shouldn't give the effect it does. So if I do
> http://localhost:8080/foo then I'll get the index servlet unless
> foo=article or blah.gif, etc. I'd rather get a NOT FOUND message for
> random URIs.
>
>


The trouble with servlet mappings is that the url pattern you can use is
not very fine grained. I hope in the future you can use regular
expressions for it.

For now would suggest introducing jsp pages. In the web.xml you then add
an entry like

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

All requests to yourdomain.org/ are handled by this index.jsp

You can drop all the servlet mappings, and your css and gif mappings
(which looks like a workaround to me) can also go.

Let me know if you need more info!
Kees de Kooter
 
Reply With Quote
 
 
 
 
Michal Dzirba
Guest
Posts: n/a
 
      09-06-2003
> <welcome-file-list>
> <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>


AFAIK Since Servlet API 2.3 a servlet can be a welcome-file
The problem is that itll probably show at the and of the url, which is
not what was needed. [The same thing happens with jsp's. ]


Michal.

 
Reply With Quote
 
Alex Martinoff
Guest
Posts: n/a
 
      09-06-2003
> The trouble with servlet mappings is that the url pattern you can use is
> not very fine grained. I hope in the future you can use regular
> expressions for it.
>
> For now would suggest introducing jsp pages. In the web.xml you then add
> an entry like
>
> <welcome-file-list>
> <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>
>
> All requests to yourdomain.org/ are handled by this index.jsp


But there is a redirect. Requests to mydomain.org/ are redirected to
mydomain.org/index.jsp. Also, there's no need for the welcome-file to
be a jsp. The welcome file can be a relative servlet url such as just
plain old index for my index servlet. The requests to mydomain.org/
are redirected to mydomain.org/index.
 
Reply With Quote
 
Alex Martinoff
Guest
Posts: n/a
 
      09-06-2003
> The trouble with servlet mappings is that the url pattern you can use is
> not very fine grained. I hope in the future you can use regular
> expressions for it.
>
> For now would suggest introducing jsp pages. In the web.xml you then add
> an entry like
>
> <welcome-file-list>
> <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>
>
> All requests to yourdomain.org/ are handled by this index.jsp


But there is a redirect. Requests to mydomain.org/ are redirected to
mydomain.org/index.jsp. Also, there's no need for the welcome-file to
be a jsp. The welcome file can be a relative servlet url such as just
plain old index for my index servlet. The requests to mydomain.org/
are redirected to mydomain.org/index.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jakatra tomcat- Ant - Apache tomcat - Difference ? Oom Computer Support 1 10-08-2007 05:13 PM
tomcat-maven-plugin problem - mvn is looking for org.apache.maven.plugins:maven-tomcat-plugin Marcin Cenkier Java 1 04-12-2006 08:00 PM
Difference between Apache Tomcat and Jakrata Tomcat twins Java 1 11-25-2005 05:57 PM
Apache Tomcat 4.1.24: problem with Tomcat Administration link Christos Gravvanis Java 0 07-07-2004 05:21 PM
Servlet front page without redirect - Tomcat 4.1 with mod_rewrite and mod_jk2 Alex Martinoff Java 2 09-07-2003 06:50 PM



Advertisments