【问题标题】:Having trouble using a form button with Spring MVC在 Spring MVC 中使用表单按钮时遇到问题
【发布时间】:2015-11-14 07:29:26
【问题描述】:

我正在尝试使用带有 spring MVC 的表单按钮。单击表单按钮后,它将带您到另一个页面(showData.jsp)。不幸的是,当我点击按钮时,什么也没有发生。我将在下面提供我的代码,感谢您的帮助。

带有表单代码的 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";
}

Dispatcher-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>

【问题讨论】:

  • 显示spring application.xml
  • 我添加了我的 dispatcher-servlet.xml。你指的是那个吗?我找不到 application.xml 文件。我的直觉告诉我,我需要在 dispatcher-servlet.xml 文件中添加一些东西,但不确定....

标签: java jsp spring-mvc


【解决方案1】:

尝试使用输入标签而不是按钮标签:

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

【讨论】:

  • 很遗憾,这没有帮助。
猜你喜欢
  • 2022-11-16
  • 1970-01-01
  • 1970-01-01
  • 2014-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多