I am planning to develop an Intranet application (Java client, JSP, SQLite)
Goal of this is that when a user clicks on the link, if the user has access (to a team which is handled in the business logic) a file should be provided for download
There is a table in the db which holds the info and below is the example row
ID | file | team | md5
1 | D:\test\output_20140915_100012.zip | Falcon | 5cceaf4cc400fd8f5c7fb4b2af754f4093369f59
where MD5 is the MD% checksum of the string "D:\test\output.zip" and not the file itself
I create the MD5 just for the sake of having random number. Reason I don't use RAND is to avoid collision (this part is trivial)
I want my URL to look like this
http://mywebserver:8080/<appname>/5cceaf4cc400fd8f5c7fb4b2af754f4093369f59
Which should be taken to
http://mywebserver:8080/<appname>/download.jsp?id=5cceaf4cc400fd8f5c7fb4b2af754f4093369f59
I am using Tomcat and I am wondering if how we could have a URL rewrite for this scenario
For Tomcat 7 you can also use tuckey . Tucket is a Java Web Filter for any compliant web application servers and allows mod_rewrite just like Apache
I would recommend to do it with Apache HTTP Server or another server. But if you want to do it only with Tomcat 7 use Tuckey UrlRewriteFilter:
A Java Web Filter for any compliant web application servers (such as Tomcat, JBoss, Jetty or Resin), which allows you to rewrite URLs before they get to your code. It is a very powerful tool just like Apache's mod_rewrite.
This filter allows you to define rules like:
Clean a url
<rule> <from>/products/([0-9]+)</from> <to>/products/index.jsp?product_id=$1</to> </rule>
eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing
from Tuckey urlrewrite example
Since Tomcat 8 you can use the rewrite valve.
The rewrite valve implements URL rewrite functionality in a way that is very similar to mod_rewrite from Apache HTTP Server.
Rewrite Valve docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With