How to create beautiful URLs (permalinks) for a Java website?

I would like to make pretty URLs for my Java web projects.

For example, I have these URLs:

  • www.mysite.com/web/controller?command=showNews&newsId=1
  • www.mysite.com/web/controller?command=showNews&newsId=2
  • www.mysite.com/web/controller?command=showNews&newsId=3

or

  • www.mysite.com/web/user.do?action=start
  • www.mysite.com/web/user.do?action=showCategory&category=videoGames§ion=AboutGames

But it is not so nice and friendly ...

I want to make such links:

  • www.mysite.com/web/2011/10/04/Steve-Jobs-iPhone-5/
  • www.mysite.com/web/2011/10/23/Facebook-Timeline/
  • www.mysite.com/web/2012/05/25/Vladimir-Putin-Russian-President/

Help me with this? How can i get it?

Java libs, .

!

: - Spring MVC Controller @RequestMapping("/Putin").

+5
1

. , :

@View(url="regex:/web/<year:\\d{4}>/<month:\\d{2}>/<day:\\d{2}>/<specifier>")
@PageScoped
public class ArticleView extends Component implements ViewComponent {

  @PathParam
  private long year;

  @PathParam
  private long month;

  @PathParam
  private long day;

  @PathParam
  private String specifier;

  @Override
  public void initialize(ViewContext context) {
    System.out.println(year+"/"+month+"/"+day+"/"+specifier);
    // Then do something
  }
}
+1

All Articles