Struts标签-<s:form>标签

本文介绍如何使用Struts框架的表单标签来简化Web应用的表单处理过程。通过示例展示了如何创建表单元素及提交按钮,并解析了Struts如何自动将表单转换为更友好的显示形式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

与jstl标准标签库类似的,struts有专属标签库 
form标签用于提交数据
  • 修改addProduct.jsp

    使用struts标签库
    <%@ 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>
  • 访问http://127.0.0.1/addProduct.jsp

    访问
    http://127.0.0.1:8080/struts/addProduct.jsp
    通过浏览器查看源码可以发现,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>
    

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值