top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to create an alias for a context name in Tomcat 6/7?

+1 vote

We have a context that includes an underscore and that is unfortunately causing problems w/ a load balancer and cookie paths. Our URLs resemble this:

Where we have deployed a war file named "the_context.war".

I'd like to somehow alias the context name so both of these urls would effectively be the same:

Ideally this would be done w/o deploying the application twice. Is this possible in Tomcat 6 and/or 7 ?

posted Jun 12, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

While it may be possible to create an "alias" my hacking into Tomcat's mapper component (that maps requests to Contexts), you will have problem if your web application calls ServletContext.getContextPath() as that information does not depend on the incoming request.

There are two typical solutions:
a) Name one URL as "the canonical" one and redirect your users from the old URL to the new one. That is to respond with HTTP status code 301 and a redirection.
b) Rewrite URLs in the incoming request and in response (if needed).

a) can be done by a simple Filter or by using a standard "rewrite" one
b) needs some mode advanced rewrite implementation

You may use UrlRewriteFilter ( )(in any version of Tomcat), RewriteValve (in Tomcat 8), mod_rewrite in Apache HTTPD server (if your Tomcat runs behind that server).

answer Jun 13, 2014 by Ankit
Thanks a lot that make sense.
Similar Questions
+1 vote

I'm trying to figure out how I can create custom session cookies. I've found the Manager interface for creating the sessions, but there's nothing about the actual session cookie. I don't see anything in the Valve interface that will let me do this either. Is this possible in Tomcat 7 (or 8?).

0 votes

Does heartbleeding bug impact on Tomcat 6.x, 7.x and 8.x ? I noticed that Tomcat native connector version 1.1.22 uses : OpenSSL 0.9.8 which doesn't have the heartbleeding bug, but 1.1.24 and 1.1.29 also include the buggy openssl.

How can I find which version of Tomcat uses which version of Tomcat native connector ? For example, how can I figure out which version of Tomcat native connector is used by Tomcat 7.0 build 47.

+2 votes

With Tomcat 7.0.40 version, we are using Tomcat DBCP for pooling connections.

We are able to pool connections for different aliases. But for one alias, connections are not pooling. The user and password is good because the same alias in apache dbcp works fine.

Why are we not able to pool any connections here?

0 votes

I'm using Tomcat6 on my web application which is running on Windows Server 2003 Standard Edition. I want to access static files (PDF) in the remote directory on the disk server (NetApp) through http address from web browser. I tried to use Windows shortcut, but It didn't work. Seems that Tomcat recognize a shortcut as a common file (.lnk) instead of a soft link. How can I access it properly through http in the IE browser?

I can only access the files if the static files are put in the local disk. I tried to use hard link and junction, but they work only on the local disk (on the same computer). I tried to modify context.xml, but it didn't succeed.
Most of the solution in the internet is a soft link from local disk to local disk.