Results 1 to 2 of 2

Thread: How to map WEB-INF to local directory

  1. #1
    Join Date
    Oct 2011
    Posts
    1

    Default How to map WEB-INF to local directory

    Hi, my project is to migrate our application from struts to spring MVC.
    In struts we can map WEB-INF to a local path for all JSP files
    <mount uriBase="/WEB-INF/" filePath="/app/tomcat/webinf/jsp/" />

    I am wondering how do I do similar mapping in spring MVC?

    Thanks.

  2. #2
    Join Date
    Dec 2010
    Posts
    315

    Default

    To display and map a JSP from the WEB-INF folder, you must declare a ViewResolver.

    For example:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:p="http://www.springframework.org/schema/p" 
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	   		http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
    
    	<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
        		p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="1"/>
        		
    </beans>
    Take note, there are different resolvers you can use depending on your needs.

    Assuming you have a URL /welcome and you want to map it to WEB-INF/jsp/welcome.jsp, your controller must have the following signature:
    Code:
    @Controller
    @RequestMapping("/")
    public class MediatorController {
    	
    	@RequestMapping("/welcome")
    	public String getPage() {
    		return "welcome";	
    	}
    }
    Of course, I have purposely remove some configuration files in this example.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •