Announcement Announcement Module
Collapse
No announcement yet.
How to map WEB-INF to local directory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X