Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

not able to check presence of remote file using JSP

 
Naresh Talluri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Iam checking one file is exists or not in server ( another server which contains pdf files ) in JSP,
code :
[code]String path ="http://files.voice............test.pdf" ;
File filePath = new File(application.getRealPath(path));
System.out.println("File exist-->"+filePath.exists());[/code]
but it is giving always false even if the file exists..

can you please let me know if you have any idea..

Thanks,
Naresh T
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An URL is not a valid file path.

Make use of ServletContext#getRealPath() to translate a relative URL to an absolute file system path.

That said, you shouldn't be writing raw Java code in JSP files. That is receipt for trouble. Write Java code in Java classes. Use for example a Servlet. In JSP you normally use taglibs and EL to control the flow and presentation.
 
Naresh Talluri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

thank you for your suggession, here i have used File filePath = new File(application.getRealPath(path)); in my JSP,
but still the problem persist.. can you please let me know what might be the possibility.

- Naresh T
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell the details. What is path? What does getRealPath() return? Is it actually valid?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another server which contains pdf files

Okay, I overlooked the fact that it is located at another server. Is it physically also another machine/filesystem? If so, using java.io is indeed not going to work. You can't go around using java.net.URLConnection and determining the response headers on a HEAD (or GET) request.
 
Naresh Talluri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you for your reply, i tried with URLConnection and it is working fine..

-Naresh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!