You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Craig R. McClanahan" <Cr...@eng.sun.com> on 2000/09/19 00:42:06 UTC

Re: HOWTO Question: Extra arguments in the URL of a GET request available to servlet via request.getPathInfo()

See intermixed comments.

"Desaulniers, Peter" wrote:

> Hi there,
>
> I am very new to trying to adapt a server from a CGI / python implementation
> to a tomcat / servlet implementation.  For backward compatibility, I would
> like to be able to support the exist URL format of the CGI / python
> implemenation. That format is:
>
> http://host:port/mycgi/start.py/arg1/.../argN
>
> I have put an entry in servlet.xml to handle the mycgi term.
>
> <Context path="/mycgi" docBase="webapps/mycgi" debug="0" reloadable="true" >
>
> </Context>
>
> Next, I have added a Servlet and Servlet-Mapping entry into the web.xml in
> ...\mycgi\Web-inf directory.
>
> <web-app>
>     <servlet>
>         <servlet-name>
>             entryPoint
>         </servlet-name>
>         <servlet-class>
>             startApp
>         </servlet-class>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>
>             entryPoint
>         </servlet-name>
>         <url-pattern>
>             *.py
>         </url-pattern>
>     </servlet-mapping>
> </web-app>
>
> This allows me to run my startApp.class servlet in the
> ...\mycgi\Web-inf\classes directory with the following URL:
>
> http://host:port/mycgi/start.py
>
> But that is not enough...
>
> I need to have n arguments available to that servlet by adding them to the
> URL and then having them available via the path_info environment data which
> the servlet has access to.
>
> So the desired URL would be of the form (for a 2 argument URL):
>
> http://host:port/mycgi/start.py/arg1/arg2
>
> And the servlet could use:
>
> request.getPathInfo()
>
> to retrieve the arguments.
>

The reason this does not work with an extension mapping is that the extension
has to be on the last element of the path -- so there won't be any path info.
See below for an alternative.

>
> My problem is twofold:
>
> 1. I don't know how to configure tomcat to run the servlet with the extra
> arguments in the URL.  When I added /arg1 to http://host:port/mycgi/start.py
> it fails to run the servlet.  Which I believe is a configuration problem.
>
> 2. It seems that when it works with http://host:port/mycgi/start.py,
> path_info from request.getPathInfo() is always NULL.   Is there some way to
> get the URL data (once I solve problem 1) in the servlet?
>

If you set up your mapping like this:

    <servlet-mapping>
        <servlet-name>entryPoint</servlet-name>
        <url-pattern>/start.py/*</url-pattern>
    </servlet-mapping>

you will get what you want -- anything after "start.py" in the request URI will
show up in getPathInfo().  The only restriction is that no other name ending in
".py" is matched.

>
> Can anyone help me with either or both of these problems.
>
> Thanks,
>
> -- Peter Desaulniers

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat