Form标签用于提交数据
1、使用struts标签库
**addProduct.jsp:**
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<body>
<s:form action="addProduct">
<s:textfield name="product.name" label="product name" />
<s:submit value="Submit" />
</s:form>
</body>
</html>
**struts.xml:**
<struts>
<package>
<action name="addProduct" class="showProduct.ProductAction" method="add">
<result name="show">show.jsp</result>
</action>
</package>
</struts>
2、访问http://127.0.0.1/addProduct.jsp,通过浏览器查看源码(F12)可以发现,struts把表单里的内容自动转换成了table:
<form id="addProduct" name="addProduct" action="addProduct.action" method="post">
<table class="wwFormTable">
<tr>
<td class="tdLabel"><label for="addProduct_product_name" class="label">product name:</label></td>
<td
><input type="text" name="product.name" value="" id="addProduct_product_name"/></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" id="addProduct_0" value="Submit"/>
</div></td>
</tr>
</table></form>
效果如图所示:

本文详细介绍了如何使用Struts标签库进行表单提交。通过示例代码展示了一个产品添加表单的创建过程,包括使用Struts标签库的addProduct.jsp页面和对应的struts.xml配置文件。文章还展示了浏览器中表单被自动转换为table形式的源码。

1729

被折叠的 条评论
为什么被折叠?



