如何使用
<form:form> </form:form>
在 Spring MVC 应用程序中使用 HTML 标签?
我没有使用.jsp。相反,我正在使用 HTML 页面。
最佳答案
您不能在 HTML 页面中使用它...
要使用<form:form>
JSP 中的标记,您必须使用 JSP 标记库:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
此标记库允许使用 Spring form
特征。示例:
<form:form
method="POST"
action="/spring-mvc-xml/addEmployee" modelAttribute="employee">
<table>
<tr>
<td><form:label path="name">Name</form:label></td>
<td><form:input path="name"/></td>
</tr>
<tr>
<td><form:label path="id">Id</form:label></td>
<td><form:input path="id"/></td>
</tr>
<tr>
<td><form:label path="contactNumber">
Contact Number</form:label></td>
<td><form:input path="contactNumber"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</form:form>
要使用此表单,您需要从 Controller 发送 Employee 类对象作为 ModelAttribute...
一个主要的剩余部分是表单元素中的所有 path 属性应与 Employee 类属性名称相同...
public class Employee {
private String name;
private long id;
private String contactNumber;
// Standard getters and setters
}
如需更多帮助,我们可以查看此链接 reference of my post .
关于java - 如何使用<表单:form> </form:form> TAG using HTML in Spring MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56764298/