可以取代jstl标签的<c:if>
主要是用于比较吧,具体属性的用法如下:
<logic:equal name="RegistrationForm" property="action" value="Create">
name="对象名称" property="属性名称" value="比较值"
你就当jsp 里面的 c:if 标签用吧 这个比 if 标签高级一点点 但差不多
如果value值和name属性的参数传递的值相等则执行
<logic:equal name="age" value="18">
<p>如果age=18,显示本段标签</p>
<logic:equal>
<logic:equal name="age" value="17">
<p>如果age=18,不显示显示本段标签</p>
<logic:equal>
实例:
如果一个jsp传递一个带参数的连接,如:<a href="javascript:alink('/command.do?method=one&name=${rows.commandName }&check=1')">
给action:
action经过接收并处理:
public ActionForward one(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String name = request.getParameter("name");
String check = request.getParameter("check");//接收连接传递的参数check=1;
name = BaseUtils.changeEncoding(name, "GBK");
check = BaseUtils.changeEncoding(check, "GBK");//如果是中文字符必须解码,这里不是必须。
CommandDao dao = new CommandDao();
List<CommandDto> list = dao.selectCommandByName(name);
if (list.size() > 0) {
request.setAttribute("exeT", (list.get(0)).getExecTime());
request.setAttribute("name", (list.get(0)).getCommandName());
}
request.setAttribute("comList", list);
request.setAttribute("num", list.size());
request.setAttribute("check", check);//此处设置check的属性值为check=1;然后给jsp页面update使用;
saveToken(request);
return mapping.findForward("update");//mapping.findForward的映射是在strust-config,xml中设置的<forward name="update" path="/commandcontrolupdate.jsp"/>。
}
在/commandcontrolupdate.jsp中使用<logic:equal name="check" value="1" >标签来判断是否满足check=1时,执行标签内的元素。
strust1的strust-config,xml中设置:
<action path="/command" name="commandForm" parameter="method" scope="request" type="com.streetlight.command.action.CommandAction" >
<forward name="add" path="/commandcontroladd.jsp"/>
<forward name="update" path="/commandcontrolupdate.jsp"/>
<forward name="list" path="/commandSearch.do"/>
<forward name="publish" path="/commandpublish.jsp"/>
<forward name="hand" path="/commandhandcontral.jsp"/>
<forward name="handinit" path="/command.do?method=handcontrolInit"/>
</action>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
以上是取出一个request属性的值进行比较,下边是取出action传回的list集合中的一个对象属性值比较:
比如 action 传回一个list集合,集合中放vo对象,vo中有两个属性name,path
<logic:iterate name="list" id="vo">
输出两个属性值:${name},${path} 这是EL表达式,可以在jsp和js中直接读取和显示${}的值。
<logic:equal name="vo" property="name" value="王刚">
这是王刚的name
</logic:equal>
</logic:iterate>
实例如下:
<logic:iterate id="rows" name="comList" indexId="rowsId">
<input type="hidden" value="${rows.id }" id="comId" name="comId"/>
<tr>
<td>
<table id="tableid_${rows.id }" width="100%">
<tr><td>
<p> 亮灯时间: ${rows.startDate} 关灯时间: ${rows.lastDate} </p>
</td></tr>
<tr><td>
<logic:equal name="rows" value="1" property ="command">
<p>策略设定: 全开</p>
</logic:equal>
<logic:equal name="rows" value="2" property ="command">
<p>策略设定: 全关</p>
</logic:equal>
<logic:equal name="rows" value="3" property ="command">
<p>策略设定: 隔灯亮</p>
</logic:equal>
</td>
</tr>
<tr>
<td colspan="3" height="15px">
<div style="border-color:#1c1d1d #1c1d1d #2e2f2f #1c1d1d;border-style:solid;border-width:1px;"></div>
</td>
</tr>
</table>
</td>
</tr>
<script>
maketime("startTime${rowsId+1 }","lastTime${rowsId+1 }");
selected("${rowsId+1 }","${rows.startDate}",2);
selected("${rowsId+1 }","${rows.lastDate}",3);
selected("${rowsId+1 }","${rows.command}",4);
</script>
</logic:iterate>
主要是用于比较吧,具体属性的用法如下:
<logic:equal name="RegistrationForm" property="action" value="Create">
name="对象名称" property="属性名称" value="比较值"
你就当jsp 里面的 c:if 标签用吧 这个比 if 标签高级一点点 但差不多
如果value值和name属性的参数传递的值相等则执行
<logic:equal name="age" value="18">
<p>如果age=18,显示本段标签</p>
<logic:equal>
<logic:equal name="age" value="17">
<p>如果age=18,不显示显示本段标签</p>
<logic:equal>
实例:
如果一个jsp传递一个带参数的连接,如:<a href="javascript:alink('/command.do?method=one&name=${rows.commandName }&check=1')">
给action:
action经过接收并处理:
public ActionForward one(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String name = request.getParameter("name");
String check = request.getParameter("check");//接收连接传递的参数check=1;
name = BaseUtils.changeEncoding(name, "GBK");
check = BaseUtils.changeEncoding(check, "GBK");//如果是中文字符必须解码,这里不是必须。
CommandDao dao = new CommandDao();
List<CommandDto> list = dao.selectCommandByName(name);
if (list.size() > 0) {
request.setAttribute("exeT", (list.get(0)).getExecTime());
request.setAttribute("name", (list.get(0)).getCommandName());
}
request.setAttribute("comList", list);
request.setAttribute("num", list.size());
request.setAttribute("check", check);//此处设置check的属性值为check=1;然后给jsp页面update使用;
saveToken(request);
return mapping.findForward("update");//mapping.findForward的映射是在strust-config,xml中设置的<forward name="update" path="/commandcontrolupdate.jsp"/>。
}
在/commandcontrolupdate.jsp中使用<logic:equal name="check" value="1" >标签来判断是否满足check=1时,执行标签内的元素。
strust1的strust-config,xml中设置:
<action path="/command" name="commandForm" parameter="method" scope="request" type="com.streetlight.command.action.CommandAction" >
<forward name="add" path="/commandcontroladd.jsp"/>
<forward name="update" path="/commandcontrolupdate.jsp"/>
<forward name="list" path="/commandSearch.do"/>
<forward name="publish" path="/commandpublish.jsp"/>
<forward name="hand" path="/commandhandcontral.jsp"/>
<forward name="handinit" path="/command.do?method=handcontrolInit"/>
</action>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
以上是取出一个request属性的值进行比较,下边是取出action传回的list集合中的一个对象属性值比较:
比如 action 传回一个list集合,集合中放vo对象,vo中有两个属性name,path
<logic:iterate name="list" id="vo">
输出两个属性值:${name},${path} 这是EL表达式,可以在jsp和js中直接读取和显示${}的值。
<logic:equal name="vo" property="name" value="王刚">
这是王刚的name
</logic:equal>
</logic:iterate>
实例如下:
<logic:iterate id="rows" name="comList" indexId="rowsId">
<input type="hidden" value="${rows.id }" id="comId" name="comId"/>
<tr>
<td>
<table id="tableid_${rows.id }" width="100%">
<tr><td>
<p> 亮灯时间: ${rows.startDate} 关灯时间: ${rows.lastDate} </p>
</td></tr>
<tr><td>
<logic:equal name="rows" value="1" property ="command">
<p>策略设定: 全开</p>
</logic:equal>
<logic:equal name="rows" value="2" property ="command">
<p>策略设定: 全关</p>
</logic:equal>
<logic:equal name="rows" value="3" property ="command">
<p>策略设定: 隔灯亮</p>
</logic:equal>
</td>
</tr>
<tr>
<td colspan="3" height="15px">
<div style="border-color:#1c1d1d #1c1d1d #2e2f2f #1c1d1d;border-style:solid;border-width:1px;"></div>
</td>
</tr>
</table>
</td>
</tr>
<script>
maketime("startTime${rowsId+1 }","lastTime${rowsId+1 }");
selected("${rowsId+1 }","${rows.startDate}",2);
selected("${rowsId+1 }","${rows.lastDate}",3);
selected("${rowsId+1 }","${rows.command}",4);
</script>
</logic:iterate>