java - Using a jsp as an img src in liferay portlet -


i have code checks xml node value , displays image if value true:

<x:if select="$person/pictureprivate != 'false'">     <c:set var="pidm">         <x:out select="$person/@pidm" />     </c:set>     <img src="<%=renderrequest.getcontextpath()%>/getpicture.jsp&amp;pidm=${pidm}"></img> </x:if> 

the jsp source post webservice:

int len; int size = 1024; byte[] buf; outputstream o = response.getoutputstream(); string pidm=request.getparameter("pidm");  //out.print("url: " + urlprop + pidm); url url = new url("myurl" + pidm); urlconnection connection = url.openconnection();  connection.setdooutput(true);  connection.setconnecttimeout(5000); connection.setreadtimeout(5000);  inputstream = connection.getinputstream();    if (is instanceof bytearrayinputstream) {   size = is.available();   buf = new byte[size];   len = is.read(buf, 0, size); }  else {   bytearrayoutputstream bos = new bytearrayoutputstream();   buf = new byte[size];   while ((len = is.read(buf, 0, size)) != -1)     bos.write(buf, 0, len);   buf = bos.tobytearray(); }   o.write(buf);    o.flush();  o.close(); 

i know webservice jsp works, because use in application. however, image doesn't load in liferay portlet, , trying right click -> view image results in apache error the requested resource not available. i'm thinking might defining src path wrong i'm not sure.

renderrequest's getcontextpath resolves portal's context, while plugin has own context. in fact, request.getcontextpath resolves portal (but please double check it): when portlet served, request handled portal. when want address resource portlet's webcontext, you'll need explicitly address , either hard-code web context of portlet (inelegant) or find how address it.

follow @ramp's comment , check getcontextpath (for both renderrequest , request) resolves , you're closer solution. if in doubt, replace hardcoded context path , continue search dynamic path.

also note won't have access portal's signed in user account in jsp if requested in way want to. you're not making use of in jsp, should fine - wanted make sure understood well


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -