user46688
user46688

Reputation: 753

how to access PDF/image/video file located in java server from a browser URL?

I have an mp4 video on my GlassFish java application server. What URL do I use to access it in a browser?

The video path in the application on the server is:

myapp/WEB-INF/videos/myvideo.mp4

I tried adding this to my web.xml file:

<servlet>
  <servlet-name>myvideo</servlet-name>
  <servlet-class>videos.myvideo.mp4</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>myvideo</servlet-name>
  <url-pattern>/myvideo</url-pattern>
</servlet-mapping>

and restart the server, then go to the URL: https://www.example.com/myapp/myvideo but that just gave this error:

java.lang.ClassNotFoundException: videos.myvideo.mp4

Obviously it's not a servlet, but not sure what else to try.

Upvotes: 0

Views: 672

Answers (1)

radimpe
radimpe

Reputation: 3215

Why are you trying to access the video as a servlet and not as a static asset, like you would an image? Using a servlet mapping is obviously wrong.

Instead if you have a running WebApp in GlassFish you should be able to access it via https://www.example.com/myapp/videos/myvideo.mp4 assuming you've put the videos folder under your webapp's j2ee root.

The j2ee root would be configured in your application.xml as the web-uri. In your case it is likely that the myapp folder is your j2ee root. So move your videos up a folder.

(Converted comment 'discussion' into an answer).

Upvotes: 1

Related Questions