0

I saw in this post that I could use the below example to define a default controller/page

@RequestMapping(value={"/content/edit", "/"}, method=RequestMethod.GET)

Unfortunately it's not working. When I open my app it shows a 404 error unless I look for /content/edit.htm

my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Spring-MVC-Dispatcher-Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/app-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Spring-MVC-Dispatcher-Servlet</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
</web-app>

2 Answers 2

0

Your servlet is mapped to "*.htm". "/" does not match that pattern, so your servlet and thus your controller has no chance of being invoked. I think you can specify the welcome file (that's what / is) in web.xml, I would have to look up how, though.

0

Your problem this in that "/content/edit.htm" is not mapping for

@RequestMapping(value={"/content/edit", "/"}, method=RequestMethod.GET).

You need

@RequestMapping(value={"/content/edit.htm", "/"}, method=RequestMethod.GET).

or

@RequestMapping(value={"/content/edit.*", "/"}, method=RequestMethod.GET).

You can choose the last option because you filter web.xml to *. htm

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.