如何使用
<form:form> </form:form>
在Spring应用程序中使用HTML标记?
我不使用.jsp。相反,,我正在使用HTML 。
发布于 2019-06-26 05:57:43
你不能在HTML页面中使用它..。
要在JSP中使用<form:form>标记,必须使用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>要使用此表单,需要将Employee类对象作为ModelAttribute从控制器发送.
一个主要的余数是表单元素中的所有路径属性都应该与Employee类属性名称相同.
public class Employee {
private String name;
private long id;
private String contactNumber;
// Standard getters and setters
}要获得更多帮助,我们可以看到这个链接我职位的参考资料。
发布于 2021-09-28 16:31:54
这是我的答案
<form:form
action="/action" modelAttribute="student">
<table>
<tr>
<td><form:label path="name">Name</form:label></td>
<td><form:input path="name"/></td>
</tr>
<tr>
<td><form:label path="email">email</form:label></td>
<td><form:input path="email"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</form:form><%@ taglib prefix=“表单”uri="http://www.springframework.org/tags/form“%>
进口标签
在控制器中
@RequestMapping("/test")
public String index1(Model model)
{
// String name1=name;
model.addAttribute("student",new Studentdata());
return "form.jsp";
}在动作URL中
@RequestMapping("/action")
public String jasper1(@ModelAttribute("student") Studentdata student)
{
System.out.print("name"+student.getName());
System.out.print("name"+student.getEmail());
return"action.jsp";
}发布于 2019-06-26 02:27:42
HTML中没有特定的<form:form> </form:form>,但是您可以这样使用它:
<form action="../store" method="post" >
// Your code
</form>https://stackoverflow.com/questions/56764298
复制相似问题