Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC: How to resolve the path to subdirectories of the root 'JSP' folder in a web application
    primarykey
    data
    text
    <p>What is a simple way to resolve the path to a JSP file that is not located in the root JSP directory of a web application using SpringMVCs viewResolvers? For example, suppose we have the following web application structure:</p> <pre><code>web-app |-WEB-INF |-jsp |-secure |-admin.jsp |-admin2.jsp index.jsp login.jsp </code></pre> <p>I would like to use some out-of-the-box components to resolve the JSP files within the <em>jsp</em> root folder and the <em>secure</em> subdirectory. I have a <code>*-servlet.xml</code> file that defines:</p> <p>an out-of-the-box, <code>InternalResourceViewResolver</code>:</p> <pre><code> &lt;bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"&gt;&lt;/property&gt; &lt;property name="prefix" value="/WEB-INF/jsp/"&gt;&lt;/property&gt; &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt; &lt;/bean&gt; </code></pre> <p>a handler mapping:</p> <pre><code>&lt;bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt; &lt;property name="mappings"&gt; &lt;props&gt; &lt;prop key="/index.htm"&gt;urlFilenameViewController&lt;/prop&gt; &lt;prop key="/login.htm"&gt;urlFilenameViewController&lt;/prop&gt; &lt;prop key="/secure/**"&gt;urlFilenameViewController&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>an out-of-the-box <code>UrlFilenameViewController</code> controller:</p> <pre><code>&lt;bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"&gt; &lt;/bean&gt; </code></pre> <p>The problem I have is that requests to the JSPs in the <em>secure</em> directory cannot be resolved, as the <code>jspViewResolver</code> only has a prefix defined as <code>/jsp/</code> and not <code>/jsp/secure/</code>.</p> <p>Is there a way to handle subdirectories like this? I would prefer to keep this structure because I'm also trying to make use of <em>Spring Security</em> and having all secure pages in a subdirectory is a nice way to do this.</p> <p>There's probably a simple way to acheive this but I'm new to Spring and the Spring MVC framework so any pointers would be appreciated.</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.
 

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