2017-10-12 82 views
0

當我點擊<a href="/login">test</a>鏈接或<input type="submit" value="Submit"/>控制器部分未加載。 Println語句不執行Spring Mvc控制器部分未加載。

<form action="/login" method="get"> 
<h2>UserName</h2><input type="text" name="userName"/> 
<input type="submit" value="Submit"/> 
</form> 
<a href="/login">test</a> 

的web.xml:

<!DOCTYPE web-app PUBLIC 
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd" > 


<web-app> 
    <display-name>Archetype Created Web Application</display-name> 
    <servlet> 
    <servlet-name>dispatcher</servlet-name> 
    <servlet-class> 
     org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 
</web-app> 

爲spring-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd"> 

    <mvc:resources mapping="/resources/**" location="/resources/" /> 
    <context:component-scan base-package="com.sample.*" /> 

    <mvc:annotation-driven /> 

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

</beans> 

控制器部分:

@Control LER

public class UserController 
{ 

    @RequestMapping("/login") 
    public void loginUser() throws Exception 
    { 
     System.out.println("Inside loginUser method"); 

    } 
} 
+0

你得到任何錯誤@Ivin拉吉? –

+0

沒有先生@KalaiselvanA .. –

+0

@IvinRaj din't我的回答幫了你嗎? – sunkuet02

回答

1

我發佈的解決方案,如果有人有相同的問題:

更改action="/login" to action="login"<a ref="/login">test</a> to <a href="<c:url value="/login" />"></a>

+0

謝謝先生@awagenhoffer –

+0

不客氣。 – awagenhoffer