You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Skijor <sk...@gmail.com> on 2007/06/03 17:40:28 UTC
context path confusion [RequestDispatcher, servlet-mapping, MVC]
There may be a work-around for this but I what I really want to know
is why it doesn't work.
I am following the MVC design pattern in building a simple test web
application using Tomcat 6.0.10 on Mac OS Tiger.
MVC pattern suggests every webapp request be handled by a servlet.
Static content rendered by forwarding the request to a jsp page.
Dynamic content is handled by java code and presentation by css (in my
app).
I am confused over the apparent inconsistent behavior observed when
specifying a servlet-mapping in web.xml with a url-pattern = '/'
against other url-patterns. Is this a bug in tomcat?
For Example:
I have a web application on my filesystem (deployed with default
build.xml) under: $CATALINA_HOME/webapps/ixania.
My web.xml file defines a servlet named BootStrap with a mapping like this:
<servlet-mapping>
<servlet-name>BootStrap</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping >
The BootStrap servlet only does one thing on an http GET request:
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/tmp.jsp");
dispatcher.forward(request, response);
tmp.jsp only contains a single string as context in the <body>: FOOBAR
When I navigate to http://localhost/ixania, I see FOOBAR in the browser.
When I add a <link> reference to tmp.jsp to locate a css file:
link href="<%= request.getContextPath() %>/css/tmp.css"
rel="stylesheet" type="text/css">
The css never gets resolved. The css is on the filesystem at
$CATALINA_HOME/ixania/css/tmp.css
When I change the url-pattern in web.xml to
<url-pattern>/ixania</url-pattern> and navigate to
http://localhost/ixania/ixania the context is display and the css is
applied.
This seems like a tomcat bug to me since I have simply substituted '/'
for '/ixania' in both the url-pattern and the actual URL.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: context path confusion [RequestDispatcher, servlet-mapping, MVC]
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Skijor,
Skijor wrote:
> <servlet-mapping>
> <servlet-name>BootStrap</servlet-name>
> <url-pattern>/</url-pattern>
> </servlet-mapping >
Note that by mapping '/' to your own servlet, you are overriding the
"default" servlet that usually serves requests for things like static
resources.
> This seems like a tomcat bug to me since I have simply substituted '/'
> for '/ixania' in both the url-pattern and the actual URL.
You should use a <welcome-file> instead of mapping '/' to your own servlet.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGYzJF9CaO5/Lv0PARAhjmAKCLzNTCM/ZjNYkaoP42AQETxIClLQCgpotb
3MwQHh0t2ynJ+BbTmmfau0I=
=TbTs
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org