春天欢迎文件

时间:2014-03-15 08:38:47

标签: java spring spring-mvc servlets welcome-file

我已经尝试过了,两个都没有用(HTTP 404)

<welcome-file-list>
    <welcome-file>/home</welcome-file>
</welcome-file-list>

<welcome-file-list>
   <welcome-file>home</welcome-file>
</welcome-file-list>
网址http://myserver.com:8080/App-0.1/home中的

工作正常

日志:

INFO:org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - 映射网址路径[/ home]到处理程序&#39; homeController&#39;

INFO:org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - 将映射的URL路径[/home.*]发送到处理程序&#39; homeController&#39;

INFO:org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - 映射的URL路径[/ home /]到处理程序&#39; homeController&#39;

2 个答案:

答案 0 :(得分:0)

确定..

package com.myapplication.controller

@Controller
public class HomeController {

private static final Logger logger =LoggerFactory.getLogger(HomeController.class);


/**
 * Simply selects the home view to render by returning its name.
 */
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(Locale locale, Model model) {

    model.addAttribute("userForm", new UserForm());
    return "home";
}

@RequestMapping(value = "/login",method = RequestMethod.POST)
 public String submitForm(@Valid UserForm  user, BindingResult result,ModelMap model) {

  if (result.hasErrors()) {
         return "home";
     }

  model.addAttribute("userForm",user);
  return "doors";

 }

@ModelAttribute("userForm")
public UserForm createModel() {
    return new UserForm();
}

}


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/web-services 
        http://www.springframework.org/schema/web-services/web-services-2.0.xsd">

<!-- Activates various annotations to be detected in bean classes -->
<context:annotation-config />

<!-- Scans the classpath for annotated components that will be auto-registered 
    as Spring beans. For example @Controller and @Service. Make sure to set the 
    correct base-package -->
<context:component-scan base-package="com.myapplication" />


<!-- Configures the annotation-driven Spring MVC Controller programming 
    model. Note that, with Spring 3.0, this tag works in Servlet MVC only! -->
<mvc:annotation-driven />

<!-- Load Hibernate related configuration -->
<!-- Here you can also add spring security context, if exist -->
<import resource="hibernate-context.xml" />

答案 1 :(得分:0)

解决方案:将@RequestMapping(value = {“/”添加到控制器