Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't do that. You can never guarantee that the WAR folder is writable or even on physical disk. For example, when the servletcontainer is configured to expand the WAR into memory instead of into disk. </p> <p>As it's apparently a temporary file, rather just use <a href="http://download.oracle.com/javase/6/docs/api/java/io/File.html#createTempFile%28java.lang.String,%20java.lang.String%29" rel="nofollow"><code>File#createTempFile()</code></a>:</p> <pre><code>File tempFile = File.createTempFile("filename", ".png"); // ... </code></pre> <p>Or use an external folder on the fixed disk file system whose absolute path is to be set as VM argument or some configuration setting.</p> <hr> <p><strong>Update</strong>: you could use a servlet to display that file. I gather that it's an image file. You can use <code>&lt;h:graphicImage&gt;</code> wherein you set the temp file's filename in the path.</p> <p>E.g. inside the bean:</p> <pre><code>this.filename = tempFile.getName(); </code></pre> <p>and then in the view:</p> <pre class="lang-html prettyprint-override"><code>&lt;h:graphicImage value="images/#{bean.filename}" /&gt; </code></pre> <p>The servlet which should listen on <code>/images/*</code> can then just look like as follows (exceptional checks are omitted for your exercise):</p> <pre><code>@WebServlet("/images/*") public class ImageServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { File file = new File(System.getProperty("java.io.tmpdir"), request.getPathInfo()); response.setHeader("Content-Type", getServletContext().getMimeType(file.getName())); response.setHeader("Content-Length", String.valueOf(file.length())); InputStream input = new FileInputStream(file); OutputStream output = response.getOutputStream(); // Now write input to output the usual way. } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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