2017-04-06 33 views
1

我的項目映射是一個行家項目,當我在Tomcat運行項目它顯示 org.springframework.web.servlet。 DispatcherServlet的noHandlerFound 警告:未找到HTTP請求與URI的映射[/ SpringLoginApplication /]在DispatcherServlet的名爲「SpringLoginApplication」警告:未找到HTTP請求與URI [/ SpringLoginApplication /]在DispatcherServlet的名爲「SpringLoginApplication」

我嘗試所有的可能性來解決,但所有的靜脈,有人可以幫我解決這個問題

my controlle R:

package com.spring.login.controller; 

     import javax.servlet.http.HttpSession; 
     import javax.validation.Valid; 

     import org.springframework.beans.factory.annotation.Autowired; 
     import org.springframework.stereotype.Controller; 
     import org.springframework.ui.ModelMap; 
     import org.springframework.validation.BindingResult; 
     import org.springframework.web.bind.annotation.*; 

     import com.spring.login.beans.Customer; 
     import com.spring.login.services.CustomerService; 
     import com.spring.login.validation.CustomerValidation; 

     @Controller 
     public class CustomerController { 

     @Autowired 
     private CustomerService customerService; 

     @RequestMapping(value="/" , method=RequestMethod.GET) 
     public String login(ModelMap model){ 
     //model.put("Info", new Customer()); 
     return "/login"; 
    } 

    @RequestMapping(value="/register", method = RequestMethod.GET) 
    public String showForm(ModelMap model){ 
    model.put("customerData", new Customer()); 
    return "/register"; 
    } 


    @RequestMapping(value= "/register", method= RequestMethod.POST) 
    public String saveForm(ModelMap model, @ModelAttribute("customerData") @Valid Customer customer, BindingResult br, HttpSession session){ 
    CustomerValidation customerValidation = new CustomerValidation(); 
    customerValidation.validate(customerValidation, br); 
    if(br.hasErrors()){ 
    return "/register"; 
    } 
    else{ 
     customerService.saveCustomer(customer); 
     session.setAttribute("customer", customer); 
     return "redirect:success"; 
     } 
    } 
    @RequestMapping(value="/logout", method = RequestMethod.GET) 
    public String logOut(ModelMap model, HttpSession session){ 

     session.removeAttribute("customer"); 
     return "redirect:login"; 
    } 

    @RequestMapping(value="/success", method = RequestMethod.GET) 
    public String logOut(ModelMap model){ 

     model.put("customer", new Customer()); 
     return "redirect:success"; 
} 

} 

我的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" > 
    <display-name>SpringLoginApplication</display-name> 
    <welcome-file-list> 
    <welcome-file>home.jsp</welcome-file> 
    <welcome-file>index.html</welcome-file> 
    </welcome-file-list> 

    <context-param> 
      <param-name>contextClass</param-name> 
      <param-value> 


    org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
      </param-value> 
    </context-param> 

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

    <servlet> 
     <servlet-name>SpringLoginApplication</servlet-name> 
     <servlet- 
    class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value> 
       /WEB-INF/SpringLoginApplication-servlet.xml 
      </param-value> 
     </init-param> 
     <init-param> 
      <param-name>contextClass</param-name> 
      <param-value> 

    org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
      </param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>SpringLoginApplication</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    <session-config> 
     <session-timeout>30</session-timeout> 
    </session-config> 
    </web-app> 

我SpringLoginApplication-servlet.xml中:

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

xsi:schemaLocation=" 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
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"> 


<context:component-scan base-package="com.spring.login.controller" /> 
<context:component-scan base-package="com.spring.login.dao" /> 
<context:component-scan base-package="com.spring.login.beans" /> 
<context:component-scan base-package="com.spring.login.services" /> 
<context:component-scan base-package="com.spring.login.validation" /> 

<mvc:annotation-driven /> 
<context:annotation-config /> 

<bean 
class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/views/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 
<bean class="com.spring.login.beans.Customer" init-method="getC_id" destroy- 
method="getC_name"> 
    <property name="c_id" value="1234"/> 
    <property name="c_name" value="Sanjay"/> 
</bean> 


</beans> 

一個工作的反應將不勝感激!

任何其他信息REQUIRED,請讓我知道

回答

0

我前幾天有同樣的問題,而且我得到了波紋管的解決方案。

@Controller 
@RequestMapping(value="/") 
public class CustomerController { 

//do your stuff here 
@RequestMapping(method=RequestMethod.GET) 
    public String login(ModelMap model){ 
    //model.put("Info", new Customer()); 
    return "/login"; 
} 

//Rest of your stuff goes here 

}

既然你已經配置了調度servlet來處理在所有可能代替你的背景下,人們一般做加入這個(/ *),所以上面提供的代碼段將工作和重定向你上下文到/你想要的登錄(如果我沒有錯)。乾杯!!!!

+0

那不行,試了一下......>。< – user7826263

相關問題