Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>We have something similar, except returning images instead of a PDF; should be a similar solution, though, I'm guessing. </p> <p>On a JSP, we have an <code>IMG</code> tag, where the <code>src</code> is set to:</p> <pre><code>&lt;c:url value="/path/getImage.do?imageId=${imageID}" /&gt; </code></pre> <p>(I'm not showing everything, because I'm trying to simplify.) In your case, maybe it would be a link, where the <code>href</code> is done in a similar way.</p> <p>That <code>getImage.do</code> maps to our JPF controller, obviously. Here's the code from the JPF <code>getImage()</code> method, which is the part you're trying to work on:</p> <pre><code>@Jpf.Action(forwards = { @Jpf.Forward(name = FWD_SUCCESS, navigateTo = Jpf.NavigateTo.currentPage), @Jpf.Forward(name = FWD_FAILURE, navigateTo = Jpf.NavigateTo.currentPage) }) public Forward getImage(final FormType pForm) throws Exception { final HttpServletRequest lRequest = getRequest(); final HttpServletResponse lResponse = getResponse(); final HttpSession lHttpSession = getSession(); final String imageIdParam = lRequest.getParameter("imageId"); final long header = lRequest.getDateHeader("If-Modified-Since"); final long current = System.currentTimeMillis(); if (header &gt; 0 &amp;&amp; current - header &lt; MAX_AGE_IN_SECS * 1000) { lResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return null; } try { if (imageIdParam == null) { throw new IllegalArgumentException("imageId is null."); } // Call to EJB, which is retrieving the image from // a separate back-end system final ImageType image = getImage(lHttpSession, Long .parseLong(imageIdParam)); if (image == null) { lResponse.sendError(404, IMAGE_DOES_NOT_EXIST); return null; } lResponse.setContentType(image.getType()); lResponse.addDateHeader("Last-Modified", current); // public: Allows authenticated responses to be cached. lResponse.setHeader("Cache-Control", "max-age=" + MAX_AGE_IN_SECS + ", public"); lResponse.setHeader("Expires", null); lResponse.setHeader("Pragma", null); lResponse.getOutputStream().write(image.getContent()); } catch (final IllegalArgumentException e) { LogHelper.error(this.getClass(), "Illegal argument.", e); lResponse.sendError(404, IMAGE_DOES_NOT_EXIST); } catch (final Exception e) { LogHelper.error(this.getClass(), "General exception.", e); lResponse.sendError(500); } return null; } </code></pre> <p>I've actually removed very little from this method, because there's very little in there that I need to hide from prying eyes--the code is pretty generic, concerned with images, not with business logic. (I changed some of the data type names, but no big deal.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload