0

Am having many xhtml pages in my application. First page that a User gets to see is named index.xhtml, when User is asked to update his Profile it will be updateProfile.xhtml etc. When I hit my application my page names gets displayed on the URL. When user is updating profile, URL will be http:/myDomain/myServlet/updateProfile.jsf.

Am interested in knowing whether its possible to map all my xhtml page names which gets displayed on the URL to some other name. For eg., in the above case, I want all the URLs which matches *.jsf pattern to be displayed to user as http:/myDomain/myServlet/myAccount.

I dont see a possible threat if a end user gets to know my page names, but still, I dont have much knowledge on Security/Hacking, so atleast I dont want to display *.jsf in my URL. Because, a user can know that am using JSF.

Vikas V
  • 3,176
  • 2
  • 37
  • 60

1 Answers1

1

In JavaServer Faces to rewrite URL you need basically a Filter. In your case your rewrite could be done by something like PrettyFaces http://ocpsoft.org/prettyfaces/.

With PrettyFaces you will be able to configure rewrite patterns and everything you need.

Edit : When creating your own Filter to redirect URL, you also need to create a ViewHandler and override the getActionURL() function so that actions will go to the new URL.

Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
  • That's good to know. Link you provided above is for Pretty Faces. But, I don't use Pretty Faces. Am using core JSF tags ('h' & 'f'). _When creating your own Filter to redirect URL_ - This is when I am using Pretty Faces or I can do this even when am using core JSF tags? Can you please provide a link which explains steps for that? – Vikas V Nov 15 '12 at 04:12
  • When using PrettyFaces you can use only base JSF (f: and h:) and take advandage of URL mapping : http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.pathparams . When creating your own Filter, you need to create a class that implements javax.servlet.Filter and declare it by annotation or web.xml, same for ViewHandler! – Alexandre Lavoie Nov 15 '12 at 04:17
  • If I write my own `ViewHandler` and override the `getActionURL`, I should return a String which is the Friendly URL that I want. Lets say I am returning `MyAccounts` as friendly URL, then it will try to find a mapping for `MyAccounts`(else it will throw 404 error). For this, if I make an entry in `web.xml` and write a `Servlet` mapping , what should be the code in the `Servlet` to display the actual contents of the page but still show the friendly URL `MyAccounts` on the URL? – Vikas V Dec 25 '12 at 14:00
  • 1
    ViewHandler are JSF things, Servlets are plain Java things. To use ViewHandler, you need to have a View, View are created by xhtml pages. In you case you'll need to create a Filter that will redirect to a View including the friendly URL in get parameter for example. – Alexandre Lavoie Dec 27 '12 at 04:39