1

I'm currently developing a Struts 2 web application that allow anonymous usage. I want that with anonymous user, the URL will be like:

http://localhost:8080/myapp

But after user logged in, the URL will be personalized base on user name, for example:

http://localhost:8080/myapp/Cuong-Doan

Please suggest me a plugin/technique that can help me to achieve it.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Doan Cuong
  • 2,594
  • 4
  • 22
  • 39

2 Answers2

1

You can try to do it with Tuckey's UrlRewriteFilter. After loging add session attribute, for example loggedUsername=Cuong-Doan. Then analyze this attribute in UrlRewriteFilter rule using session-attribute parameter of condition element. If it is present -> do redirect, add it to the URL using backreferences.

Maksym Demidas
  • 7,707
  • 1
  • 29
  • 36
1

Personalized could be done via setting the parameter specifying the persona. Looking at the URLs in the question I decided to give you imagination about technique used to reproduce SEO optimized URLs. This technique is called "Parameters after action names". For example to map your persona with the action you can use

@Action(value = "/*", params = {"person", "{1}"}) 

so, after that action is mapped you will get the information about person via the person parameter that could be used in the action.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • 1
    +1, @Doan this is the answer, no plugins needed. See my related answer too: http://stackoverflow.com/questions/15855831/how-to-map-long-rest-urls-in-struts2-using-struts2-rest-plugin/15875522#15875522 – Andrea Ligios Apr 09 '13 at 12:13
  • @DoanCuong if you have multiple actions then you can use wildcards – Roman C Apr 09 '13 at 12:16
  • @Roman C thank you for suggestion. May I ask one question? According to your answer, I suppose to put `{"person", "{1}"}` in every action to achieve `http://localhost:8080/myapp/Cuong-Doan/{action name}`, am I right? @AndreaLigios Thank you for your suggest. Would you mind to put your comment as an answer so I can upvote it? – Doan Cuong Apr 09 '13 at 12:18
  • @DoanCuong you could use action name as a second parameter, and so on. See http://stackoverflow.com/questions/14411736/passing-parameters-in-url-without-query-string-in-struts2/14415902#14415902 – Roman C Apr 09 '13 at 12:23
  • @DoanCuong One more comment using wildcards with named variable is not possible due to the pattern matchers are mutually exclusive. – Roman C Apr 09 '13 at 12:33
  • @DoanCuong, just upvote RomanC answer... if you want to upvote my comment, simply upvote my other (linked) answer :) – Andrea Ligios Apr 09 '13 at 12:40