Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Multiple JSP folders in Spring MVC enabled application

Posted on 2008-06-22
3
Medium Priority
?
3,235 Views
Last Modified: 2013-11-24
I'm working on a Spring MVC project where I put all the jsp files in WEB-INF/views

What I want to do is to add more folders for the jsp's, say views/user, views/admin, views/files etc, to keep all the jsp files more organized.

This doesn't seem to work with the InternalResourceViewResolver, since you can only specify one folder for all the views (jsp's). Is there a workaround or an alternative viewResolver to solve this issue?

I've pasted a code snippet below of the viewResolver from dispatch-servlet.xml

Thank you
<bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
		<property name="prefix" value="/WEB-INF/views/" />
		<property name="suffix" value=".jsp" />
</bean>

Open in new window

0
Comment
Question by:temj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 92

Expert Comment

by:objects
ID: 21842635
you would create another instance of that view resolver, but the problem will be that that resolver needs to be last so that is not possible in this case.

0
 
LVL 3

Accepted Solution

by:
shaz_ earned 1000 total points
ID: 21846248
mm like objects mentioned... it might not be possibly directly.. however just on somewat of a side note i would suggest using a tilesView instead, then u wont have to worry about the folder issue.. u can have as many subfolders as u wish.
something like
//servlet-config.xml file would be something like this
   <bean id="viewResolver"
     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="requestContextAttribute" value="requestContext"/>
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles.TilesView"/>
   </bean>
 
   <bean id="tilesConfigurer"  class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
          <property name="factoryClass" value="org.apache.struts.tiles.xmlDefinition.I18nFactorySet"/>
          <property name="definitions">
            <list>
                <value>/WEB-INF/tiles-config.xml</value>
            </list>
          </property>
   </bean>
 
 
// your tiles-config.xml would be something like
 
<tiles-definitions>
 
<!-- for single page u would have something like -->
<definition name="loginPage" path="/WEB-INF/jsp/login.jsp"/>
 
<!-- for a proper tilesd def would be as follows -->
<definition name="Main" path="/WEB-INF/jsp/index.jsp">
    <put name="include-position" value="/WEB-INF/jsp/include/include.jsp"/>
    <put name="header-position" value="/WEB-INF/jsp/layouts/header.jsp"/>
    <put name="body-position" value="/WEB-INF/jsp/data.jsp"/> 
    <put name="nav-position" value="/WEB-INF/jsp/navcomponents/leftnavigation.jsp"/>
    <put name="footer-position" value="/WEB-INF/jsp/layouts/footer.jsp"/>
</definition>
 
 
</tiles-definitions>
 
 
 
//and then in your controller or wherever u can just 
 
 new ModelAndView("loginPage");

Open in new window

0
 

Author Comment

by:temj
ID: 21847306
Works perfectly :)
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question