Web tier: servlets, JSP, Web frameworks: URL Encode
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.
Take a look at java.net.URLDecoder and java.net.URLEncoder. I think what you want is URLDecoder.
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,
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
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).
(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.
Thanks a lot Andy,
Some how i am able to solve the problem now. Thanks for the help.
u can go to JAVA API and look for Encode , Yes u can encode the path of URL