URL Encode
  1. URL Encode (5 messages)

    Hi,
    Can we use URL Encode in JSP file to remove special characteres such as %20 (equivalent to blank space), which are the part of the HTTP URL.
    I guess similar thing is used in ASP, do we have something like that in JSP too.

    Thanks
    Nitu

    Threaded Messages (5)

  2. URL Encode[ Go to top ]

    Take a look at java.net.URLDecoder and java.net.URLEncoder. I think what you want is URLDecoder.

    Andy
  3. URL Encode[ Go to top ]

    Thanks,
    but still my problem remains the same.
    let me explain u what exactly i want to do:
    there is a file name with spaces, for example abc 123.txt,
    now i want to display this file in the browser in a separate window. i am using javascript window.open(), where i am passing this file name. So what happens is the space in abc 123.txt is getting converted to abc%20123.txt, which is not existing and i am getting the error as "FILE NOT FOUND".
    I hope i have made my problem quite clear. It would be great help if u could suggest some thing. I am using JSP and weblogic server.
    Thank you very much
    nitu
  4. URL Encode[ Go to top ]

    I'm not sure how you're passing the file name to the JSP, but somehow you have to isolate the file name in a String variable. Once you do that, just use java.net.URLDecoder.decode(filename).

    e.g.

    (assuming file name is being passed as a request parameter, i.e. http://myserver/foo.jsp?filename=abc%20123.txt)

    In your JSP:

    <%@ page import="java.net.*" %>
    <%
    ...
    String encodedFilename = request.getParameter("filename"); // isolate the filename in a variable
    String decodedFilename = URLDecoder.decode(encodedFilename);
    ...
    %>

    I would also suggest that you use the absolute path to access the file.

    Andy
  5. URL Encode[ Go to top ]

    Thanks a lot Andy,
    Some how i am able to solve the problem now. Thanks for the help.
    nitu
  6. URL Encode[ Go to top ]

    u can go to JAVA API and look for Encode , Yes u can encode the path of URL