How is it right to issue a statistical content in jetty?
I write an app for servlet/jsp under jetty. I can't figure out how to get pictures on the page, etc. I did it with a separate survivor who tied to the url "img," and the pictures asked.
"img?=someimg.png" , but in this approach I don't like the following: (1) The entire content has to be stored somewhere in the directory jetty, how to read it from a warrior when I collect and start jetty from the idea I never understood. ♪
(2) I think it's just some kind of colt. ♪ ♪
String pathToImg = "/webapp/ROOT/images/";//этот путь до war-ника я тоже не понимаю BufferedInputStream streamImg = new BufferedInputStream(new FileInputStream(pathToImg)); byte array = new byte[streamImg.available()]; streamImg.read(array); BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream()); bos.write(array);
Actually, it's the right thing to do in jetty. ♪ ?
I'll add a few words about the crutch.
webapp/ROOT- Web application of the jetty application server, I believe. It's default on the root context.
This ROOT is not a special one, and you can use it to your discretion. As an option to put the same pictures in there and to refer them to pages from other annexes. But in return, these applications acquire some kind of collateral dependence, which is not good. Better make the ROOT portal to other established applications.
As has already been observed, all web applications on the java are available in url type. http://server/app_name ♪ /app_name is the context of the annex.
The addresses of all pages and other web-based applications begin with the context:
http://server/app_name/index.jsp ♪ http://server/app_name/images/someimg.png
And this ROOT is available at the address. http://server/ His context is just /
The name of the annex, its context (and as a consequence of url) may not coincide. You can even set the root / your annex, and this ROOT can turn it off.
But why would you want to turn around with these?
BufferedInputStream- Who? I don't understand.
The picture is also added on the page as follows:
In your example, the picture is downloaded from the file using knowledge of where the file is physically located. It's wrong to rely on that knowledge. He can change and work. And as shown above, don't really do that.