How to avoid junk character in URL?

Splash Forums PrettyFaces Users How to avoid junk character in URL?

This topic contains 3 replies, has 2 voices, and was last updated by  Christian Kaltepoth 9 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #18780



    I am using pretty faces for URL rewriting.

    In my url I have few string parameter. Those string parameter has some space in between.

    In pretty-config.xml I defiened as below.

    <url-mapping id=3D"hotelreview">
    <pattern value=3D"/hotel-detail/#{hotelSearchResultsBean.hotelName}/#{hotelSearchResultsBean.cityName}" />
    <view-id value=3D"/pages/hotel/hotelReview.xhtml" />

    The URL rewriting working perfectly. However the string parameter space taking as %20 in web browser URL.

    How to avoid the %20 in URL.

    For example I need to show as below

    Expected URL: http://localhost:8080/b2c/hotel-detail/Dar Al Ghufran/Makkah

    Current URL: http://localhost:8080/b2c/hotel-detail/Dar%20Al%20Ghufran%20/Makkah


    The problem is that many characters (like space characters for example) are not allowed in URLs. So to use these characters you have to escape them. %20 is the escaped version of a space character. So it is absolutely correct to have %20 instead of spaces in an URL.

    Look here for some more detailed explanation for the encoding:

    If you don’t want such escaped characters in your URL, you will have to prevent that such characters (like spaces) are present in your path parameters. A very simple approach would be to replace spaces by underscores or something like this.

    I hope this helps :)





    Yes I got the point. It shows %20 in browser URL, but in java request.getRequestURL() gives original URL.

    Any how i have replaced the space to ‘-‘ character for better view. :)


    PrettyFaces 3.x doesn’t support conversion of path parameters. That’s something you get with Rewrite / PrettyFaces 4.0.

    Currently you could simply use special getters and setters. Something like:

    <url-mapping id=3D"hotelreview">
    <pattern value=3D"/hotel-detail/#{hotelSearchResultsBean.prettyHotelName}/#{hotelSearchResultsBean.prettyCityName}" />
    <view-id value=3D"/pages/hotel/hotelReview.xhtml" />

    And the bean:

    public class HotelSearchResultsBean {

    private String hotelName;

    /* regular getters / setters */

    public String getPrettyHotelName() {
    return hotelName.replace(' ', '-');

    public void setPrettyHotelName(String str) {
    this.hotelName = str.replace('-', ' ');


    But please not that this will of cause break if you have both – and space characters in your strings.

Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.