Audio in a webbpage is usually to be included by the HTML <embed>
element (which uses the platform default player) or the HTML <object>
element (wherein you can specify a more specific player for which the webbrowser can eventually automagically download the necessary plugin software). See also this w3schools tutorial.
Either way, it should point to an URL which returns the audio stream. This can be just a static file in the public webcontent, next to the JSP file. E.g. http://example.com/context/file.wav. But when the audio file is stored outside the public webcontent or in a database, then you'd like to stream it via a Servlet. Basically just get an InputStream
of it (using e.g. FileInputStream
) and then write it to the OutputStream
of the response along a correct set of response headers.
Noted should be that JSP is irrelevant in this particular question. It's just a view technology providing a template to write HTML in and send it to the webbrowser.
That said, websites which plays audio are generally considered annoying and generally scare off visitors. Keep this in mind if you consider User Experience important.