0

I my code I am trying to access the file abc123.pdf like http://localhost:8080/pdf/abc123.pdf . I have set up the the project in eclipse and takes the control of tomcat installation .My project is present under C:\apache-tomcat-6.0.45\wtpwebapps\ . How can access the file abc123.pdf where shall i keep it so that it can be accessed by http://localhost:8080/pdf/abc123.pdf

Ashish Banker
  • 2,243
  • 3
  • 20
  • 21

2 Answers2

0

You can deploy the webapp as root webapp, see: deploy webapp from Eclipse to Tomcat root context

Resources that should be accessable directly have to be in the web-folder of your project. Something like this:

C:\[PATH_TO_WORKSPACE]\[WEBAPPNAME]\web\pdf\abc123.pdf

After deployment it should be here:

C:\apache-tomcat-6.0.45\wtpwebapps\[WEBAPPNAME]\pdf\abc123.pdf
Timo
  • 36
  • 3
  • \pdf\abc123.pdf will be on local path like C:/users/pdf However I want to access it over http protocall like http://localhost:8080/pdf/abc123.pdf – Ashish Banker Aug 10 '18 at 12:22
  • If you don't want the pdf in your project, you can write a servlet that reads the file with a FileInputStream and returns the byte stream to the user (with appropriate HTTP headers). – Timo Aug 10 '18 at 12:33
  • how can I do it like below I dont want to write Servlet – Ashish Banker Aug 10 '18 at 12:56
0
  1. Read the file in your tomcat
  2. write this file to HttpServletResponse
  3. only support the GET method
  4. when browser get this response which with byte stream in ResponseBody it will start to download
Destiny.Wang
  • 169
  • 8