SFernando
SFernando

Reputation: 1124

how to change url pattern in struts action

domain/Forum_show.action?pg=2&forum=java

How do I rewrite that to:

domain/forum/java/pg/2

Upvotes: 0

Views: 3322

Answers (3)

Pigueiras
Pigueiras

Reputation: 19356

Both are good answers but you can use UrlRewritefilter. In this link there is an example of how to use in a Struts2 application.

Upvotes: 2

admenva
admenva

Reputation: 2421

You may want to check Struts REST Plugin, which purpose is to follow Ruby on Rails URL style (just as you want).

Upvotes: 2

Steven Benitez
Steven Benitez

Reputation: 11055

Use the URL structure you like right from the start. The ability to map to any URL structure is a feature of the Servlet API.

Also, you don't need to have an action extension (the .action part) in Struts2. In my opinion, creating bogus extensions never made sense.

Here are a few pages where I have talked about using Named Variable Pattern Matching in order to provide prettier URLs. I use this technique in all of my Struts2 apps and it yields much nicer URLs similar to your second example.

Upvotes: 4

Related Questions