Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>How exactly did you deploy your application?</p> <p><code>ServletContext().getRealPath("/")</code> may return null if it is not deployed as exploded. Read the link below for further information. However, the method to configure this may not be the same for your servlet container.</p> <p><a href="http://ananthkannan.blogspot.com/2009/12/servletcontextgetrealpath-returns-null.html" rel="noreferrer">http://ananthkannan.blogspot.com/2009/12/servletcontextgetrealpath-returns-null.html</a></p> <p><strong>Updates</strong></p> <blockquote> <p>Can someone tell me what's the difference in deploying the WAR as exploded?</p> </blockquote> <p>When you deploy the war file as exploded, the servlet container, e.g. Tomcat, will extract the content of war file into a temporary folder and runs everything from that folder so the <code>{WEB_ROOT]/_images/avatars/[myid].jpg</code> is actually exist on file system (hard disk). Therefore, you can actually get the real path (as it already says in the name of the method). However, if your servlet container does not extract the war file, the folder you are looking for is inside the war file and there is no real path to it so it will return <code>null</code>.</p> <blockquote> <p>Is it something not recommended to do on a production server? Advantages/disadvantages?</p> </blockquote> <p>You should not store dynamic contents under your source folder or the webroot folder (webapp) since servlet container will use it temporarily and delete it or change to a new folder when you redeploy your web application. You will likely lost the dynamic data you put into these folders. The web root folder is usually designed for storing static content, which means content you don't want to change - for example, graphic images for your web component like background images, css, etc.</p> <p>The usual method for storing user data is to somehow create a folder in userspace and put your dynamic data in there. However, you will not be able to serve the content of the folder outside webroot. You will need to write your own static servlet to pipe the data when they are requested. This is quite complicated for a beginner.</p> <p>The easiest way for implementing your own static servlet to serve dynamic content is to extend the static servlet of your servlet container. However, your code will highly depend on the servlet container you are deploying to.</p> <p>Since you are going to provide a REST interface for resizing images, you can create a controller which reads in the original images from the dynamic content folder, do the resizing, save it as a temporary file or flush the content of the <code>HttpResponse</code>.</p>
 

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