Bhavin Patel
Bhavin Patel

Reputation: 75

how to rewrite or generate url like twitter and facebook in java

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

Answers (2)

Lincoln
Lincoln

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

Bozho
Bozho

Reputation: 597324

There are quite a lot of options. Almost every framework can do that. Here are a few options:

  • use the UrlRewriteFilter
  • spring-mvc allows you to map a method to /${username}
  • map a servlet to / and handle the request.getRequestURI() or request.getPathInfo()

Upvotes: 4

Related Questions