struts2标签用法随笔

1、s:textfield的label可以设置显示的文字,但是不能嵌套调用s:property,这样可以解决

<s:textfield name="name" ><s:property value="#st.index+1"/></s:textfield>

2、s:iterator 遍历的序号

<s:iterator value="type.subs" status="st">
<s:textfield name="name" ><s:property value="#st.index+1"/></s:textfield>
</s:iterator>

3、不使用s:property怎样取action中的值

<input type="hidden" name="type.id" value="${type.id}"></input>

4、scriplet取出action中的变量

scriplet就是jsp中的java代码

"type"即action中的变量
<%@ page language="java" import="java.util.*,com.life.hibernate.bean.Type" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<% 
Type type= (Type)request.getAttribute("type");
for(int i=0;i<type.getSubs().size();i++){%>
<s:hidden name="type.subs[<%=i %>].id"></s:hidden>
<s:textfield name="type.subs[<%=i %>].name"></s:textfield>
<%} %>

 5、struts2中s:textfield的value,nam不能嵌套使用scriplet,""中的内容不进行任何转义

但是html的input标签的value ,name可以

<input type="text" name="type.subs[<%=i %>].name" value="<%=i%>"></input>

Done

原文地址:https://www.cnblogs.com/xingyyy/p/3918650.html