2015-11-14 61 views
1

我試圖在Spring MVC中使用表單按鈕。一旦你點擊表單按鈕,它會帶你到另一個頁面(showData.jsp)。不幸的是,當我點擊按鈕時沒有任何反應。我會在下面提供我的代碼,並感謝您的幫助。在使用Spring MVC的表單按鈕時遇到問題

JSP文件用的形式的代碼:

<form:form method="POST" action="${pageContext.request.contextPath}/showPage"> 

    <button type="button" value="button" name="button"> Click Here!</button> 

</form:form> 

控制器代碼:

@RequestMapping(value = "/showPage", method = RequestMethod.POST) 
public String printWelcome() { 

    return "showData"; 
} 

分配器一的servlet

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

    <context:component-scan base-package="com.springapp.mvc"/> 

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

show spring application.xml – sunysen

+0

我添加了我的dispatcher-servlet.xml。那是你所指的?我找不到一個application.xml文件。我的直覺告訴我,我需要在dispatcher-servlet.xml文件中添加一些東西,但不知道.... –

回答

0

嘗試使用輸入標籤而不是按鈕標籤:

<form:form method="POST" action="${pageContext.request.contextPath}/showPage"> 
    <input type="submit" value="Click here!" name="button" /> 
</form:form> 
+0

不幸的是,沒有幫助。 –