No mapping found for HTTP request with URI Spring

2019-01-17 04:31发布

Here's my Web.xml

dispatcherServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/servlet-context.xml 1

<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

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

my servlet-context.xml

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

And lastly the Handler class. which is under com.springexample.controller.impl

@Controller
public class IndexControllerImpl implements IndexController {

    @RequestMapping("/")
    public String index() {

        return "index";
    }
}

However on going to localhost:8080/projectname/

it returns a 404 error.

 Jul 27, 2013 8:18:31 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/tasklist/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcherServlet'
Jul 27, 2013 8:18:37 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/tasklist/index] in DispatcherServlet with name '

Here is my project structure

Project Structure

7条回答
Ridiculous、
2楼-- · 2019-01-17 05:28
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Hey Please use / in your web.xml (instead of /*)

查看更多
登录 后发表回答