You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason Novotny <JD...@lbl.gov> on 2001/03/02 03:40:34 UTC

newbie servlet deploy question

I would like to be able to access a servlet with the URL
http://localhost:8080/demo

However, it only works if I go to
http://localhost:8080/demo/servlet/demo

    I have the following in server.xml and web.xml respectively:

<Context path="/demo"
                 docBase="webapps/demo"
                 crossContext="true"
                 debug="0"
                 reloadable="true"
                 trusted="false" >
        </Context>

BTW, should I comment out or use the following in some way?
<RequestInterceptor
            className="org.apache.tomcat.request.InvokerInterceptor"
            debug="0" prefix="/servlet/" />


My web.xml in webapps/demo/WEB_INF/web.xml has the following:

<servlet>
      <servlet-name>demo</servlet-name>
      <servlet-class>org.demo.DemoServlet</servlet-class>
    </servlet>

<servlet-mapping>
      <servlet-name>demo</servlet-name>
      <url-pattern>/demo</url-pattern>
    </servlet-mapping>

So I would like to be able to use <form action="/demo">  and have the
servlet invoked.


    Thanks very much, Jason




--
Jason Novotny               novotny@george.lbl.gov
Home: (510) 704-9917        Work: (510) 486-8662
NERSC Distributed Computing http://www-didc.lbl.gov




Re: newbie servlet deploy question

Posted by Milt Epstein <me...@uiuc.edu>.
On Fri, 2 Mar 2001, Bo Xu wrote:

> Jason Novotny wrote:
> 
> > I would like to be able to access a servlet with the URL
> > http://localhost:8080/demo
> >
> > However, it only works if I go to
> > http://localhost:8080/demo/servlet/demo
> >
> >     I have the following in server.xml and web.xml respectively:
> >
> > <Context path="/demo"
> >                  docBase="webapps/demo"
> >                  crossContext="true"
> >                  debug="0"
> >                  reloadable="true"
> >                  trusted="false" >
> >         </Context>
> >
> > BTW, should I comment out or use the following in some way?
> > <RequestInterceptor
> >             className="org.apache.tomcat.request.InvokerInterceptor"
> >             debug="0" prefix="/servlet/" />
> >
> > My web.xml in webapps/demo/WEB_INF/web.xml has the following:
> >
> > <servlet>
> >       <servlet-name>demo</servlet-name>
> >       <servlet-class>org.demo.DemoServlet</servlet-class>
> >     </servlet>
> >
> > <servlet-mapping>
> >       <servlet-name>demo</servlet-name>
> >       <url-pattern>/demo</url-pattern>
> >     </servlet-mapping>
> >
> > So I would like to be able to use <form action="/demo">  and have the
> > servlet invoked.
> 
> Hi :-)  with jakarta-tomcat-4.0-b1(standalone, JDK1.3, winnt40),
> I find:
[ ... ]

Re: newbie servlet deploy question

Posted by Bo Xu <bo...@cybershop.ca>.
Jason Novotny wrote:

> I would like to be able to access a servlet with the URL
> http://localhost:8080/demo
>
> However, it only works if I go to
> http://localhost:8080/demo/servlet/demo
>
>     I have the following in server.xml and web.xml respectively:
>
> <Context path="/demo"
>                  docBase="webapps/demo"
>                  crossContext="true"
>                  debug="0"
>                  reloadable="true"
>                  trusted="false" >
>         </Context>
>
> BTW, should I comment out or use the following in some way?
> <RequestInterceptor
>             className="org.apache.tomcat.request.InvokerInterceptor"
>             debug="0" prefix="/servlet/" />
>
> My web.xml in webapps/demo/WEB_INF/web.xml has the following:
>
> <servlet>
>       <servlet-name>demo</servlet-name>
>       <servlet-class>org.demo.DemoServlet</servlet-class>
>     </servlet>
>
> <servlet-mapping>
>       <servlet-name>demo</servlet-name>
>       <url-pattern>/demo</url-pattern>
>     </servlet-mapping>
>
> So I would like to be able to use <form action="/demo">  and have the
> servlet invoked.
>
>     Thanks very much, Jason
>
> --
> Jason Novotny               novotny@george.lbl.gov
> Home: (510) 704-9917        Work: (510) 486-8662
> NERSC Distributed Computing http://www-didc.lbl.gov
> [...]

Hi :-)  with jakarta-tomcat-4.0-b1(standalone, JDK1.3, winnt40),
I find:

*  in webapps/myapp/WEB_INF/web.xml:
    -  if I define the following servlet definitions:
       <servlet-name>sn_0</servlet-name>
       <servlet-name>sn_1</servlet-name>
       ...
      <servlet-name>sn_m</servlet-name>

     - and I define the following servlet-mapping:
       <servlet-mapping>
          <servlet-name>sn_0</servlet-name>
          <url-pattern>/up_0</url-pattern>
       </servlet-mapping>
       <servlet-mapping>
          <servlet-name>sn_1</servlet-name>
          <url-pattern>/up_1</url-pattern>
       </servlet-mapping>
       ...
       <servlet-mapping>
          <servlet-name>sn_m</servlet-name>
          <url-pattern>/up_m</url-pattern>
       </servlet-mapping>
       i.e., I map sn_j to up_j  (0<=j<=m)

*  then :
    - if  NOONE "from up_0 to up_m" = "/", we can use the
       following to invoke MyServlet:
       http://localhost:8080/myapp/servlet/MyServlet
       and:
       http://localhost:8080/myapp/up_0
       ...
       http://localhost:8080/myapp/up_m
       i.e., now we have m+1 "named" servlet definitions and
       1 "default(non-named)" servlet definition.

    - if ANYONE "from up_0 to up_m" = "/", now I find perhaps
       it is what you need (i suppose up_i="/", 0<=i<=m):
      % we still can use the  following to invoke MyServlet:
       http://localhost:8080/myapp/servlet/MyServlet
       and:
       http://localhost:8080/myapp/up_x    (0<=x<=m, x ! = i)
       http://localhost:8080/myapp/YYY    (YYY!=up_x, YYY
           can be anything :-)   )
       i.e., we can use:
       http://localhost:8080/myapp
       http://localhost:8080/myapp/
       http://localhost:8080/myapp/hahahahaha    //hahahahaha :-)
       ...
       and thay all invoke that servlet defnition whose name is
       "sn_i" .


Bo
Mar.02, 2001




Re: newbie servlet deploy question

Posted by Bo Xu <bo...@cybershop.ca>.
Jason Novotny wrote:

> I would like to be able to access a servlet with the URL
> http://localhost:8080/demo
>
> However, it only works if I go to
> http://localhost:8080/demo/servlet/demo
>
>     I have the following in server.xml and web.xml respectively:
>
> <Context path="/demo"
>                  docBase="webapps/demo"
>                  crossContext="true"
>                  debug="0"
>                  reloadable="true"
>                  trusted="false" >
>         </Context>
>
> BTW, should I comment out or use the following in some way?
> <RequestInterceptor
>             className="org.apache.tomcat.request.InvokerInterceptor"
>             debug="0" prefix="/servlet/" />
>
> My web.xml in webapps/demo/WEB_INF/web.xml has the following:
>
> <servlet>
>       <servlet-name>demo</servlet-name>
>       <servlet-class>org.demo.DemoServlet</servlet-class>
>     </servlet>
>
> <servlet-mapping>
>       <servlet-name>demo</servlet-name>
>       <url-pattern>/demo</url-pattern>
>     </servlet-mapping>
>
> So I would like to be able to use <form action="/demo">  and have the
> servlet invoked.
>
>     Thanks very much, Jason
>
> --
> Jason Novotny               novotny@george.lbl.gov
> Home: (510) 704-9917        Work: (510) 486-8662
> NERSC Distributed Computing http://www-didc.lbl.gov
> [...]

Hi :-)  with jakarta-tomcat-4.0-b1(standalone, JDK1.3, winnt40),
I find:

*  in webapps/myapp/WEB_INF/web.xml:
    -  if I define the following servlet definitions:
       <servlet-name>sn_0</servlet-name>
       <servlet-name>sn_1</servlet-name>
       ...
      <servlet-name>sn_m</servlet-name>

     - and I define the following servlet-mapping:
       <servlet-mapping>
          <servlet-name>sn_0</servlet-name>
          <url-pattern>/up_0</url-pattern>
       </servlet-mapping>
       <servlet-mapping>
          <servlet-name>sn_1</servlet-name>
          <url-pattern>/up_1</url-pattern>
       </servlet-mapping>
       ...
       <servlet-mapping>
          <servlet-name>sn_m</servlet-name>
          <url-pattern>/up_m</url-pattern>
       </servlet-mapping>
       i.e., I map sn_j to up_j  (0<=j<=m)

*  then :
    - if  NOONE "from up_0 to up_m" = "/", we can use the
       following to invoke MyServlet:
       http://localhost:8080/myapp/servlet/MyServlet
       and:
       http://localhost:8080/myapp/up_0
       ...
       http://localhost:8080/myapp/up_m
       i.e., now we have m+1 "named" servlet definitions and
       1 "default(non-named)" servlet definition.

    - if ANYONE "from up_0 to up_m" = "/", now I find perhaps
       it is what you need (i suppose up_i="/", 0<=i<=m):
      % we still can use the  following to invoke MyServlet:
       http://localhost:8080/myapp/servlet/MyServlet
       and:
       http://localhost:8080/myapp/up_x    (0<=x<=m, x ! = i)
       http://localhost:8080/myapp/YYY
       (    YYY!=up_x, YYY can be anything :-)   )
       i.e., we can use:
       http://localhost:8080/myapp
       http://localhost:8080/myapp/
       http://localhost:8080/myapp/hahahahaha    //hahahahaha :-)
       ...
       and thay ALL invoke the Same servlet defnition whose name
       is "sn_i" .


Bo
Mar.02, 2001







Re: newbie servlet deploy question

Posted by Jason Novotny <JD...@lbl.gov>.
    Thanks, Jan

    I actually read your great document plus all the docs in Tomcat- actually
I'm trying to design a web app very much like the one in chapter 9 of the
kolb and fields book.

The idea is to have a central controller servlet- DemoServlet that gets
invoked initially by the user. I was hoping to use localhost:8080/demo, but
as you say, it doesn't seem setup for this. (although in the chapter they
claim on page 275 to have mapped FaqAdminServlet to /faqtool- later they use
<form action="/faqtool" ...> to reinvoke the controller servlet)- which is
very much what I want to do-

    In your opinion is it easier in the long run to map onto /demo/demo?

    Ultimately, I want to be able to invoke the servlet and refer to html,jsp
without caring where the web app was deployed or site specific settings of
server.xml.

    Thanks, Jason


Jan Labanowski wrote:

> You may want to read about servlet URLs ramapping in my
>    http://www.ccl.net/cca/software/UNIX/apache/tomcatfaq.shtml
> Howver, I am not sure it will gonna work...
> You can have it remapped to http://localhost:8080/demo/demo
> but what you want is to have null path in the context to correspond
> to your servlet... You probably still do not know what you want {:-)}.
> But it will come with a sacrifice of reading stuff on Tomcat, the
> Servlet 2.1 spec and JSP 1.1 spec on the JavaSun. It is all in there...
>
>  <servlet>
>    <servlet-name>DemoServletto</servlet-name>
>    <servlet-class>org.demo.DemoServlet</servlet-class>
>  </servlet>
>
>  <servlet-mapping>
>    <servlet-name>DemoServletto</servlet-name>
>    <url-pattern>demo</url-pattern>
>  </servlet-mapping>
>
> You may want to add
>
>  <servlet-mapping>
>    <servlet-name>DemoServletto</servlet-name>
>    <url-pattern>/</url-pattern>
>  </servlet-mapping>
>
> and see if this will work for
>    http://localhost:8080/demo
> But again... You only think you want it... But in fact you do not want it.
>
> On Thu, 1 Mar 2001, Jason Novotny wrote:
>
> >
> > I would like to be able to access a servlet with the URL
> > http://localhost:8080/demo
> >
> > However, it only works if I go to
> > http://localhost:8080/demo/servlet/demo
> >
> >     I have the following in server.xml and web.xml respectively:
> >
> > <Context path="/demo"
> >                  docBase="webapps/demo"
> >                  crossContext="true"
> >                  debug="0"
> >                  reloadable="true"
> >                  trusted="false" >
> >         </Context>
> >
> > BTW, should I comment out or use the following in some way?
> > <RequestInterceptor
> >             className="org.apache.tomcat.request.InvokerInterceptor"
> >             debug="0" prefix="/servlet/" />
> >
> >
> > My web.xml in webapps/demo/WEB_INF/web.xml has the following:
> >
> > <servlet>
> >       <servlet-name>demo</servlet-name>
> >       <servlet-class>org.demo.DemoServlet</servlet-class>
> >     </servlet>
> >
> > <servlet-mapping>
> >       <servlet-name>demo</servlet-name>
> >       <url-pattern>/demo</url-pattern>
> >     </servlet-mapping>
> >
> > So I would like to be able to use <form action="/demo">  and have the
> > servlet invoked.
> >
> >
> >     Thanks very much, Jason
> >
> >
> >
> >
> > --
> > Jason Novotny               novotny@george.lbl.gov
> > Home: (510) 704-9917        Work: (510) 486-8662
> > NERSC Distributed Computing http://www-didc.lbl.gov
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, email: tomcat-user-help@jakarta.apache.org
> >
>
> Jan K. Labanowski            |    phone: 614-292-9279,  FAX: 614-292-7168
> Ohio Supercomputer Center    |    Internet: jkl@osc.edu
> 1224 Kinnear Rd,             |    http://www.ccl.net/chemistry.html
> Columbus, OH 43212-1163      |   http://www.osc.edu/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org

--
Jason Novotny               novotny@george.lbl.gov
Home: (510) 704-9917        Work: (510) 486-8662
NERSC Distributed Computing http://www-didc.lbl.gov




Re: newbie servlet deploy question

Posted by Jan Labanowski <jk...@osc.edu>.
OK, I found few minutes before my head hit the keyboard...
I am not coy, I am overworked... And lengthy explanations take time to type...

On Thu, 1 Mar 2001, Milt Epstein wrote:

> On Thu, 1 Mar 2001, Jan Labanowski wrote:
> 
> > You may want to read about servlet URLs ramapping in my
> >    http://www.ccl.net/cca/software/UNIX/apache/tomcatfaq.shtml
> > Howver, I am not sure it will gonna work...
> > You can have it remapped to http://localhost:8080/demo/demo
> > but what you want is to have null path in the context to correspond
> > to your servlet... You probably still do not know what you want {:-)}.
> > But it will come with a sacrifice of reading stuff on Tomcat, the 
> > Servlet 2.1 spec and JSP 1.1 spec on the JavaSun. It is all in there...
> > 
> [ ... ]
> > 
> > and see if this will work for  
> >    http://localhost:8080/demo
> > But again... You only think you want it... But in fact you do not want it.
> 
> OK, stop being coy, tell us why he doesn't want it :-).  (Because I
> want it too ... at least, I think I do :-).

Because if you assign a null path to your chosen servlet you will not be
able to serve anything else from this context from Tomcat.
I did not actually try it, but I assume that if you do
 <servlet-mapping>
    <servlet-name>someServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
i.e., when you map a servlet to / then each and every URL mapped to this
context and served by Tomcat will result in serving the someServlet.
Out goes packages, hierachy, JSPs and subdirs...
Of course, it has its uses (e.g., with MVC paradigm, when each URL goes
to a servlet, and then servlets forwards it to other stuff using forward call
within the container), but I suspect this was not a goal here, was it?
That is why I said what I said...

So the way to do it is to use mod_rewrite. In your httpd.conf you would put
something like:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/demo$ /demo/servlet/someServlet [R]
RewriteRule ^/demo/$ /demo/servlet/someServlet [R]
</IfModule>

And this will rewrite the URL 
    http://whatever.com/demo
    http://whatever.com/demo/
to
    http://whatever.com/demo/servlet/someServlet

while it leaves other stuff alone... This way you do not remap all your
context to a single servlet, but you just remap the single URL.

Jan
jkl@osc.edu

> 
> 
> > On Thu, 1 Mar 2001, Jason Novotny wrote:
> > 
> > > 
> > > I would like to be able to access a servlet with the URL
> > > http://localhost:8080/demo
> > > 
> > > However, it only works if I go to
> > > http://localhost:8080/demo/servlet/demo
> > > 
> > >     I have the following in server.xml and web.xml respectively:
> > > 
> > > <Context path="/demo"
> > >                  docBase="webapps/demo"
> > >                  crossContext="true"
> > >                  debug="0"
> > >                  reloadable="true"
> > >                  trusted="false" >
> > >         </Context>
> > > 
> > > BTW, should I comment out or use the following in some way?
> > > <RequestInterceptor
> > >             className="org.apache.tomcat.request.InvokerInterceptor"
> > >             debug="0" prefix="/servlet/" />
> > > 
> > > 
> > > My web.xml in webapps/demo/WEB_INF/web.xml has the following:
> > > 
> > > <servlet>
> > >       <servlet-name>demo</servlet-name>
> > >       <servlet-class>org.demo.DemoServlet</servlet-class>
> > >     </servlet>
> > > 
> > > <servlet-mapping>
> > >       <servlet-name>demo</servlet-name>
> > >       <url-pattern>/demo</url-pattern>
> > >     </servlet-mapping>
> > > 
> > > So I would like to be able to use <form action="/demo">  and have the
> > > servlet invoked.
> > 
> 
> Milt Epstein
> Research Programmer
> Software/Systems Development Group
> Computing and Communications Services Office (CCSO)
> University of Illinois at Urbana-Champaign (UIUC)
> mepstein@uiuc.edu
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org
> 

Jan K. Labanowski            |    phone: 614-292-9279,  FAX: 614-292-7168
Ohio Supercomputer Center    |    Internet: jkl@osc.edu 
1224 Kinnear Rd,             |    http://www.ccl.net/chemistry.html
Columbus, OH 43212-1163      |    http://www.osc.edu/


Re: newbie servlet deploy question

Posted by Milt Epstein <me...@uiuc.edu>.
On Thu, 1 Mar 2001, Jan Labanowski wrote:

> You may want to read about servlet URLs ramapping in my
>    http://www.ccl.net/cca/software/UNIX/apache/tomcatfaq.shtml
> Howver, I am not sure it will gonna work...
> You can have it remapped to http://localhost:8080/demo/demo
> but what you want is to have null path in the context to correspond
> to your servlet... You probably still do not know what you want {:-)}.
> But it will come with a sacrifice of reading stuff on Tomcat, the 
> Servlet 2.1 spec and JSP 1.1 spec on the JavaSun. It is all in there...
> 
[ ... ]
> 
> and see if this will work for  
>    http://localhost:8080/demo
> But again... You only think you want it... But in fact you do not want it.

OK, stop being coy, tell us why he doesn't want it :-).  (Because I
want it too ... at least, I think I do :-).


> On Thu, 1 Mar 2001, Jason Novotny wrote:
> 
> > 
> > I would like to be able to access a servlet with the URL
> > http://localhost:8080/demo
> > 
> > However, it only works if I go to
> > http://localhost:8080/demo/servlet/demo
> > 
> >     I have the following in server.xml and web.xml respectively:
> > 
> > <Context path="/demo"
> >                  docBase="webapps/demo"
> >                  crossContext="true"
> >                  debug="0"
> >                  reloadable="true"
> >                  trusted="false" >
> >         </Context>
> > 
> > BTW, should I comment out or use the following in some way?
> > <RequestInterceptor
> >             className="org.apache.tomcat.request.InvokerInterceptor"
> >             debug="0" prefix="/servlet/" />
> > 
> > 
> > My web.xml in webapps/demo/WEB_INF/web.xml has the following:
> > 
> > <servlet>
> >       <servlet-name>demo</servlet-name>
> >       <servlet-class>org.demo.DemoServlet</servlet-class>
> >     </servlet>
> > 
> > <servlet-mapping>
> >       <servlet-name>demo</servlet-name>
> >       <url-pattern>/demo</url-pattern>
> >     </servlet-mapping>
> > 
> > So I would like to be able to use <form action="/demo">  and have the
> > servlet invoked.
> 

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
mepstein@uiuc.edu


Re: newbie servlet deploy question

Posted by Jan Labanowski <jk...@osc.edu>.
You may want to read about servlet URLs ramapping in my
   http://www.ccl.net/cca/software/UNIX/apache/tomcatfaq.shtml
Howver, I am not sure it will gonna work...
You can have it remapped to http://localhost:8080/demo/demo
but what you want is to have null path in the context to correspond
to your servlet... You probably still do not know what you want {:-)}.
But it will come with a sacrifice of reading stuff on Tomcat, the 
Servlet 2.1 spec and JSP 1.1 spec on the JavaSun. It is all in there...

 <servlet>
   <servlet-name>DemoServletto</servlet-name>
   <servlet-class>org.demo.DemoServlet</servlet-class>
 </servlet>
 
 <servlet-mapping>
   <servlet-name>DemoServletto</servlet-name>
   <url-pattern>demo</url-pattern>
 </servlet-mapping>

You may want to add

 <servlet-mapping>
   <servlet-name>DemoServletto</servlet-name>
   <url-pattern>/</url-pattern>
 </servlet-mapping>

and see if this will work for  
   http://localhost:8080/demo
But again... You only think you want it... But in fact you do not want it.

On Thu, 1 Mar 2001, Jason Novotny wrote:

> 
> I would like to be able to access a servlet with the URL
> http://localhost:8080/demo
> 
> However, it only works if I go to
> http://localhost:8080/demo/servlet/demo
> 
>     I have the following in server.xml and web.xml respectively:
> 
> <Context path="/demo"
>                  docBase="webapps/demo"
>                  crossContext="true"
>                  debug="0"
>                  reloadable="true"
>                  trusted="false" >
>         </Context>
> 
> BTW, should I comment out or use the following in some way?
> <RequestInterceptor
>             className="org.apache.tomcat.request.InvokerInterceptor"
>             debug="0" prefix="/servlet/" />
> 
> 
> My web.xml in webapps/demo/WEB_INF/web.xml has the following:
> 
> <servlet>
>       <servlet-name>demo</servlet-name>
>       <servlet-class>org.demo.DemoServlet</servlet-class>
>     </servlet>
> 
> <servlet-mapping>
>       <servlet-name>demo</servlet-name>
>       <url-pattern>/demo</url-pattern>
>     </servlet-mapping>
> 
> So I would like to be able to use <form action="/demo">  and have the
> servlet invoked.
> 
> 
>     Thanks very much, Jason
> 
> 
> 
> 
> --
> Jason Novotny               novotny@george.lbl.gov
> Home: (510) 704-9917        Work: (510) 486-8662
> NERSC Distributed Computing http://www-didc.lbl.gov
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org
> 

Jan K. Labanowski            |    phone: 614-292-9279,  FAX: 614-292-7168
Ohio Supercomputer Center    |    Internet: jkl@osc.edu 
1224 Kinnear Rd,             |    http://www.ccl.net/chemistry.html
Columbus, OH 43212-1163      |    http://www.osc.edu/


Re: newbie servlet deploy question

Posted by David Crooke <da...@convio.com>.
mod_rewrite is your friend - it's a steep learning curve but worth it

Milt Epstein wrote:

> On Thu, 1 Mar 2001, Jason Novotny wrote:
>
> > I would like to be able to access a servlet with the URL
> > http://localhost:8080/demo
> >
> > However, it only works if I go to
> > http://localhost:8080/demo/servlet/demo
> [ ... ]
>
> How timely!  I just joined the list yesterday, and this is exactly one
> of the questions I was going to ask, since I'm trying to do the same
> thing.  I have managed to get close to what I want, but not quite.


Re: newbie servlet deploy question

Posted by Milt Epstein <me...@uiuc.edu>.
On Thu, 1 Mar 2001, Jason Novotny wrote:

> I would like to be able to access a servlet with the URL
> http://localhost:8080/demo
> 
> However, it only works if I go to
> http://localhost:8080/demo/servlet/demo
[ ... ]

How timely!  I just joined the list yesterday, and this is exactly one
of the questions I was going to ask, since I'm trying to do the same
thing.  I have managed to get close to what I want, but not quite.

I tried some similar things as you with a context in the server.xml
and with servlet names and mappings in web.xml without luck.

However, I did find this question in the FAQ-o-matic at jakarta.apache.org:

http://jakarta.apache.org:8080/jyve-faq/Turbine/screen/DisplayQuestionAnswer/action/SetAll/project_id/2/faq_id/12/topic_id/43/question_id/532

It's a bit cryptic, but it suggests two ways of doing this: One, have
an index page (jsp or html) that does a redirect to the servlet, or
two, use Apache's mod_rewrite.

Now, I tried the first of these, using both a META Refresh in an
index.html file and a RequestDispatcher forward() in an index.jsp
file, and it basically worked either way.  That is, it got it to the
right place from just a "http://localhost/demo" URL.  The problem is
that it changed the Location to "http://localhost/demo/servlet/demo",
which I'd like to avoid.

Now, I'm not familiar with mod_rewrite (and I don't currently have it
installed), so I don't know if it provides a cleaner way to do this
and/or avoids the above problem.  Maybe you or someone else here knows
the answer to that.

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
mepstein@uiuc.edu