Reputation: 181
my directory structure looks like this. i want to apply an image present in the resources folder(or any other folder) to my servlet ..
the code:
out.println("<body background='/resources/a.jpg'>");
but this is not loading up the image onto the webpage. i have tried placing it in src ,,,and accessing it via
out.println("<body background='/a.jpg'>");
but still nothing works.am i doing something wrong here? one more thing - the image works fine in other standalone webpages i create. i have also tried placing it directly besides the class file..that doesnt work either.
?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>second</display-name>
<servlet>
<servlet-name>ram</servlet-name>
<servlet-class>pack.MyServlet</servlet-class>
<init-param>
<param-name>data</param-name>
<param-value>a.jpg</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ram</servlet-name>
<url-pattern>/run</url-pattern>
</servlet-mapping>
</web-app>
Upvotes: 1
Views: 3739
Reputation: 99
Make sure the resources folder is viewable to the end user. I would try a test image and see if you can view it in the browser e.g:
http://localhost/myimages/1.jpg
If the above displays then you know that it is correctly getting access to the image.
Upvotes: 0
Reputation: 630
You have to add your resources folder to the list of source folders.
Right Click -> Build Path -> Use as source folder
If you don't, then Eclipse won't copy the folder into the output folder and you can't access them in the way you tried to do.
Upvotes: 1
Reputation: 322
Make sure that "resources" folder is at classpath of your web application.
Upvotes: 0