You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Chris Bruce <ch...@yahoo.com> on 2000/03/23 03:57:50 UTC
Servlet as default
Is it possible to have a servlet replace index.html in a subdirectory?
If so can someone let me know how.
Regards,
Chris Bruce
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
Re: Servlet as default
Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Chris Bruce wrote:
> Is it possible to have a servlet replace index.html in a subdirectory?
> If so can someone let me know how.
>
One approach would be to use the servlet mappings (in the WEB-INF/web.xml file
under your application's document root) to map the name of the subdirectory to
your servlet. For example, let's assume that you are modifying the default
context, and you had the following stuff in your web.xml file:
<web-app>
...
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.mycompany.MyServlet</servlet-class>
</servlet>
...
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/catalog</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/catalog/*</url-pattern>
</servlet-mapping>
...
</web-app>
Now, any request like this:
http://localhost:8080/catalog
or like this:
http://localhost:8080/catalog/extra/stuff
will be mapped to your servlet, and you can use request.getPathInfo() to see
any information that was included after the name of the servlet (null for the
first request, and "/extra/stuff" for the second request. NOTE: You would
not need a real "catalog" subdirectory under your document root, because the
servlet would be generating all of those responses.
>
> Regards,
>
> Chris Bruce
>
Craig McClanahan