Reputation: 75
how to rewrite or generate url like twitter and facebook in java....
Example : https://www.facebook.com/username, https://www.twitter.com/username
is there any java framework for this?
If anyone's got any ideas on how I could do this, or examples to help me that would be great!
Upvotes: 4
Views: 529
Reputation: 3191
I would use OCPsoft PrettyFaces or OCPsoft Rewrite for this:
With PrettyFaces:
create WEB-INF/pretty-config.xml
<url-mapping>
<pattern value="/#{username}" />
<view-id value="/profile.jsp" />
</url-mapping>
This will automatically put the value of the URL "username" into the request parameter named "username"
With Rewrite:
Here is the same thing using Rewrite, which is a bit more explicit, but also more powerful.
ConfigurationBuilder.begin()
.addRule(Join.path("/{username}").to("/profile.jsp")
.where("username").bindsTo(Request.parameter("username")));
I hope this helps.
~Lincoln
Upvotes: 0
Reputation: 597324
There are quite a lot of options. Almost every framework can do that. Here are a few options:
UrlRewriteFilter
/${username}
/
and handle the request.getRequestURI()
or request.getPathInfo()
Upvotes: 4