jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Context Root be only /  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Context Root be only /  " Watch "Context Root be only /  " New topic

Context Root be only /

amar desai

Joined: Feb 18, 2011
Posts: 3
I think I read in Sun spec that the context root has to start with '/' and end with string.

This is what I'm trying to do and maybe some other suggestions can be made.
I have a tookit (RAD 6.0).
The code base has image references to /flash, /images, etc. On the server environment there is an HTTP server and an plugin-cfg that will be able to serve those images,
however on my toolkit (IDE), I don't have the luxury to install an IHS and setup a plugin config ( I can put its the effort I"m trying to avoid).

So what I did was create a servlet with a context root of "/flash" and I have flash content in that Web App.
This works great,
but now i have /images reference, as well. However, I don't want to create another servlet for that.

So I was thinking of this approach.
Have the context root "/" so that when the request in the code is something like <img src="/images/1/blah.jpg"/>
it will know to go to my servlet, and then serve the image.

However, I'm getting errors.

So what I was thinking was to use URLRewrite servlet and then rewrite /flash to another servlet or another location.

However, this is all predicated on using context root as "/" only.

Basically I need to host images /images/...
and I'm not sure if this is possible without installing a webserver.

Thanks in advance
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63843

Wow, that's just Byzantine in its complexity. Why not back up and explain what you are trying to accomplish in the first place? It's likely it doesn;t need to be that complicated.

P.S. Servlets do not have context roots, web applications do.

[Asking smart questions] [About Bear] [Books by Bear]
amar desai

Joined: Feb 18, 2011
Posts: 3
Hi Bear -
Sure let me start from the top.
We have development environment. This has RAD 6.0 as the IDE. and a websphere test server configured.
We have an EAR and WArs as part of our project setup.
Now when we start the server and hit the url http://localhost/online/sale/index.jsp Our page doesn't render completely, (flash, images) are missing.
This is because the creative team directly puts static content on the web server(its not part of the WAR).

So in the index.jsp has <img src="/images/logo.jpg"/> which will say webgroup/virtual host not setup in toolkit console.

There is a suggestion of installing a webserver,and using the plugin-cfg.xml but I'm trying to avoid that since our dev toolkit is in a vm.

So what I would like to do is be able to have our toolkit test server be able to recognize /images/.. and host it.
and there is a /flash folder as well.

Let me know if you have any other questions.

Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
You should be able to define a web application which serves as the "root" or "default" web application.

For sure you can do it in Tomcat - you define the context root as "" (empty string)

I'm not sure if/how you can do it in WebSphere, but try setting a context root of empty string or, /
See if you have an already existing one (access your server via the browser to see if anything comes up)

If you CAN specify the default/root web application then you just need to stick your /images and /flash directories there and it should act pretty much the same as the one with a webserver in front.
amar desai

Joined: Feb 18, 2011
Posts: 3
Hi Stefan -
Thank you for your reply.
I read its possible with Tomcat.
Also, I'm doing this via RAD 6.0; which is the IDE, that I'm trying to get this context root to work.

What I did do is this. in the dynamic web project; I made it "/" only (It would not allow for empty).
When I do this. it seems to be going in an infinite loop.
What I plan on doing next is to make the context root "/" and then create a URL mapping to hit the servlet.

The servlet I have created gets the path and creates a requestDispatcher and forwards the request to that. If you would like I can post the code.

but it seems to work when I have a context root defined and and url mapping.

I'll keep you posted on what happens when I try this out.

If you have any other suggestions please let me know.

Do you know for Tomcat the default application is using a servlet, or is it just a dummy servlet?

I agree. Here's the link: http://aspose.com/file-tools
subject: Context Root be only /
It's not a secret anymore!