Announcement Announcement Module
Collapse
No announcement yet.
how can spring mvc mapping to /* Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how can spring mvc mapping to /*

    I'm curious how can springMVC mapping to /*

    I tried my example, one servlet which mapping to "/*" just render one jsp page "/WEB-INF/jsps/hello.jsp"

    Code:
    	
    <servlet>
    	<servlet-name>helloServlet</servlet-name>
    	<servlet-class>my.HelloServlet</servlet-class>
    	<load-on-startup>1</load-on-startup>
    </servlet>
    
    <servlet-mapping>
    	<servlet-name>helloServlet</servlet-name>
    	<url-pattern>/*</url-pattern>
    </servlet-mapping>
    and the java code is:

    Code:
    public class HelloServlet extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response){
            request.getRequestDispatcher("/WEB-INF/jsps/hello.jsp").forward(request, response);
        }
    }
    but this will failed with infinite loop

    Since the helloServlet mapping to /*, it will also catch the requestDispatcher's forward and cause the infinitely loop.

    How do springMVC resolve this issue?

  • #2
    It will only pass through the servlet again if the file cannot be found/rendered... Also if you are loading images etc in your jsp those will also hit the servlet...

    Comment

    Working...
    X