I have a portlet that I am hot deploying. In the root of the portlet I have a directory called 'images' and one called 'templates'. Within the portlet i dispatch to various JSP files (in doView, doEdit, etc) that are located in 'templates'. <br /><br />How do I reference the images in 'images' from any of my JSP files? <br /><br />i.e. <img src=" ??? "><br />Any help appriciated,<br /><br />- Andrew<br />
<br />
<br /><br />I also couldn't able to access my images, but I found the solution, which is to wrote a servlet which sends back the image or any file requested (Of course I tryed out many possible solution like encodeURL...,context related stuffes but neither work)<br /><br />so the servlet I wrote lookes like this:<br /><br />protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {<br /><br /><br />ServletContext con=getServletConfig().getServletContext();<br />String pic=(String)request.getParameter("pic");<br />System.out.println("Desired picture: "+pic);<br /><br />/// My dir structure looks like this: jsp<br /><br /><br />String name=con.getRealPath("/images/"+pic); //<br />System.out.println("RealPath: "+name);<br /><br />File file=new File(name);<br />System.out.println("the path is: "+name);<br />ServletOutputStream ostr = response.getOutputStream();<br />BufferedOutputStream bstr = new BufferedOutputStream(ostr);<br /><br />InputStream is = new FileInputStream(file);<br /><br /><br />long length = file.length();<br />byte[] bytes = new byte[(int)length];<br />int offset = 0;<br />int numRead = 0;<br />while (offset < bytes.length<br />&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0)<br />{<br /><br />offset += numRead;<br />}<br />bstr.write(bytes);<br />bstr.close();<br />is.close();<br /><br />}<br /><br />than in the jsp I use this code to get the file:<br /><br /><img id="pic" src="http://localhost:8080/portlets/myservlet?pic=boat.gif" height="200" width="250" alt=""><br />