views:

67

answers:

2

web.xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spitter-servlet.xml</param-value>
</context-param>

<servlet>
    <servlet-name>spitter</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>spitter</servlet-name>
    <url-pattern>*.jsp</url-pattern>
</servlet-mapping>

spitter-servlet.xml

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <value>
            /home=homeController
        </value>
    </property>
</bean>

<bean
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="order" value="1"></property>
</bean>

<bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView"></property>

    <property name="prefix" value="/WEB-INF/jsp/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

<bean name="homeController" class="org.SpringMvcExample.homeController"></bean>

homeController.java

public class homeController {
    @RequestMapping( { "/", "/home" })
    public String showHomePage(Map<String, Object> model) {     
        System.out.println("I am here");
        model.put("spittles", new String("This is ramesh"));
        return "home";
    }
}

Why i am not able to see the home.jsp??

home.jsp is placed in the path:WEB-INF/jsp/home.jsp

I am entering the url as http://localhost:8080/SpringMvcExample/home.jsp

and the error is : resource not found.

Whats wrong here??

Please help me..

Thanks in Advance

A: 

Try "home" instead of "/home" in the controller @RequestMapping.

duffymo
when i changed it to `home` the method `showHomePage` was not invoked at all for the requst `http://localhost:8080/SpringMvcExample/home.jsp`
javanoob
+1  A: 

I think Uro's answer was almost right - you shouldn't use <url-pattern>*.jsp</url-pattern> for DispatcherServlet, because it conflicts with JSP-based views (though /*, as Uro suggested, conflicts too). Try to use *.html or *.do.

axtavt
Great man..I struggled the whole week end to resolve this problem..kudos man. Could you tell me why `*.jsp` is not allowed? Thanks for your time.
javanoob
Uro first commented for this question and i replied for that..but now i dont see his answer..I am surprised where r u seeing uros comments?
javanoob
Somewhere deep inside a servlet container there is a servlet mapped to `*.jsp`. This servlet is responsible for rendering JSP pages. If you override `*.jsp` mapping, JSP pages (including your views) can't be rendered any more. What's about Uro's answer, 10k+ users can see deleted posts.
axtavt