0

I'm just trying to create a simple spring web app. When I try to navigate to http://localhost:8080/spring-test/VIEW/VIEW I receive 404 error :

HTTP Status 404 - /spring-test/VIEW/VIEW

type Status report

message /spring-test/VIEW/VIEW

description The requested resource (/spring-test/VIEW/VIEW) is not available.

Is my below config correct ?

TestController.java :

package com;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("VIEW")
public class TestController {

    @RequestMapping("VIEW")
    public String showView(final ModelMap argMap) {
        return "test.jsp";
    }

}

applicationContext.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


 <bean id="myController" class="com.TestController">

</bean>

 <bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
        <property name="order" value="0" />
        <property name="portletModeMap">
            <map>
                <entry key="view" value-ref="myController" />
            </map>
        </property>
    </bean>


</beans>

web.xml :

<?xml version="1.0" encoding="UTF-8"?>

<web-app
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID"
    version="2.5">

    <display-name>Spring3MVC</display-name>


    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/*.xml</param-value>
    </context-param>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
</web-app>

Project layout :

enter image description here

2
  • try changing<entry key="view" to <entry key="VIEW" Commented Oct 4, 2012 at 13:53
  • @Satya I tried that and same result Commented Oct 4, 2012 at 13:57

3 Answers 3

1

I may be wrong but your serlvet mapping seems to redirect to your spring servlet if the URL ends with html. See if accessing /spring-test/VIEW/VIEW.html gets you the same error.

Sign up to request clarification or add additional context in comments.

Comments

1
<mvc:annotation-driven /> is missing 

Have a look from here

Comments

1

I needed to change servlet mapping to :

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Kudos to spring MVC servlet mapping

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.