Encode an URL with Play 2

后端 未结 3 2017
一个人的身影
一个人的身影 2021-02-07 14:40

How can I encode an URL in a template with Play 2?

I search a helper like this:

urlEncode doesn\'t work now
         


        
3条回答
  •  被撕碎了的回忆
    2021-02-07 15:10

    As I can see in linked ticked it will be resolved in Play 2.1

    Quickest solution is placing ,method(s) for that in you controller (Application.java in this sample)

    public static String EncodeURL(String url) throws java.io.UnsupportedEncodingException {
        url = java.net.URLEncoder.encode(url, "UTF-8");
        return url;
    }
    
    public static String EncodeURL(Call call) throws java.io.UnsupportedEncodingException {
        return EncodeURL(call.toString());
    }
    

    and then using it in the view as required at the moment:

    
        Encoded url form router  
    Encoded url from string
    Url mixed normal+encoded

提交回复
热议问题