java spring mvc中的404错误

时间:2018-02-03 18:27:06

标签: java spring spring-mvc tomcat

我正在构建一个Java Spring Web应用程序,并在从Eclipse运行时获得404 error,tomcat中的manager部分显示应用程序已部署,并且控制台也未显示任何错误。

有人可以在这里帮助并告诉缺失的链接吗?

Dispatacher Servlet

这里使用Spring bean的链接 - 删除它以使其干净

<mvc:default-servlet-handler/>
<context:component-scan base-package="net.kzn.onlineshopping.controller"/>

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

<!-- loading static resources -->
<mvc:annotation-driven/>

<mvc:resources location="/assets/" mapping="/resources/**"/>
</beans>

页面控制器

package net.kzn.onlineshopping.controller;

....Spring imports...

@Controller
public class PageController {

    @RequestMapping(value= {"/","/home","/index"})
    public ModelAndView index() {

        ModelAndView mv = new ModelAndView("page");
        mv.addObject("title","Home");
        mv.addObject("userClickHome","true");
    return mv;
    }

    @RequestMapping(value= "/about")
    public ModelAndView about() {

        ModelAndView mv = new ModelAndView("page");
        mv.addObject("title","About us");
        mv.addObject("userClickAbout","true");
    return mv;
    }

    @RequestMapping(value= "/contact")
    public ModelAndView contact() {

        ModelAndView mv = new ModelAndView("page");
        mv.addObject("title","Contact us");
        mv.addObject("userClickContact","true");
    return mv;
    }
}

Web.xml文件的代码

    <display-name>Archetype Created Web Application</display-name>

    <!-- Configuring front Controller -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

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

</web-app>

0 个答案:

没有答案