Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
cyklus cyklus
Referencing images in portlet
23 de junio de 2005 19:32
Respuesta

cyklus cyklus

Ranking: New Member

Mensajes: 6

Fecha de incorporación: 23 de junio de 2005

Mensajes recientes

I have a portlet that I am hot deploying. In the root of the portlet I have a directory called &#39;images&#39; and one called &#39;templates&#39;. Within the portlet i dispatch to various JSP files (in doView, doEdit, etc) that are located in &#39;templates&#39;. <br /><br />How do I reference the images in &#39;images&#39; from any of my JSP files? <br /><br />i.e. &lt;img src=&quot; ??? &quot;&gt;<br /><br /><br />Any help appriciated,<br /><br />- Andrew<br />
blue-genie blue-genie
Referencing images in portlet
24 de junio de 2005 7:55
Respuesta

blue-genie blue-genie

Ranking: Junior Member

Mensajes: 42

Fecha de incorporación: 5 de mayo de 2005

Mensajes recientes

should be as simple as img src=&#39;http://yourdomainname/foldername/imgname etc.
asv asv
Referencing images in portlet
25 de junio de 2005 7:56
Respuesta

asv asv

Ranking: New Member

Mensajes: 3

Fecha de incorporación: 21 de junio de 2005

Mensajes recientes

blue-genie:<br /><br />It is not a desirable way because you will have dependecies on server name. <br />If application will run on another app server you will have to change the server name on each page.<br /><br />Does anybody know how to get this url programmatically?
cyklus cyklus
Referencing images in portlet
28 de junio de 2005 15:24
Respuesta

cyklus cyklus

Ranking: New Member

Mensajes: 6

Fecha de incorporación: 23 de junio de 2005

Mensajes recientes

Here is the solution:<br /><br />String image = renderResponse.encodeURL(renderRequest.getContextPath() + &quot;/images/&lt;image name&gt;&quot;);<br /><br />&lt;img src=&quot;&lt;%=image%&gt;&quot;&gt;<br /><br /><br />This lets you put the images inside your portlet application.<br /><br />- Andrew
MissleMan MissleMan
Referencing images in portlet
22 de septiembre de 2005 1:35
Respuesta

MissleMan MissleMan

Ranking: New Member

Mensajes: 9

Fecha de incorporación: 21 de septiembre de 2005

Mensajes recientes

I have a portlet that I am hot deploying. In the root of the portlet I have a directory called &#39;images&#39; and one called &#39;templates&#39;. Within the portlet i dispatch to various JSP files (in doView, doEdit, etc) that are located in &#39;templates&#39;. <br /><br />How do I reference the images in &#39;images&#39; from any of my JSP files? <br /><br />i.e. &lt;img src=&quot; ??? &quot;&gt;<br />Any help appriciated,<br /><br />- Andrew<br />

<br />
<br /><br />I also couldn&#39;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(&quot;pic&quot;);<br />System.out.println(&quot;Desired picture: &quot;+pic);<br /><br />/// My dir structure looks like this: jsp<br /><br /><br />String name=con.getRealPath(&quot;/images/&quot;+pic); //<br />System.out.println(&quot;RealPath: &quot;+name);<br /><br />File file=new File(name);<br />System.out.println(&quot;the path is: &quot;+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 &lt; bytes.length<br />&amp;&amp; (numRead=is.read(bytes, offset, bytes.length-offset)) &gt;= 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 />&lt;img id=&quot;pic&quot; src=&quot;http://localhost:8080/portlets/myservlet?pic=boat.gif&quot; height=&quot;200&quot; width=&quot;250&quot; alt=&quot;&quot;&gt;<br />