jsp--el/c/ognl/struts标签开发案例对比

来源:互联网 发布:飞思卡尔单片机入门 编辑:程序博客网 时间:2024/06/05 03:29
 el必须存在域中,应用范围是java。ognl必须 在struts2的标签中使用,有局限${sessionScope.loginUser}<s:property: value="#session.loginUser"/>form 表单中 <s:textfield label="User :" name="res.user.id" value="%{#session.loginUser.id}"></s:textfield> bookList等列表问题 不需要往session中存,直接在页面中提供属性同时提供getter、setter方法即可 但是实体类一般要放在session中,比如user,topic(在response中用到),而且在存session之前需要获取完整的user,以便后续取出来使用 比如topic 在responseForm页面中取出topic.title。我们之前需要通过getTopicById获取完整的topic,然后再在responseForm中使用<hr>empty的用法<p> // 下方的设置<center>    [    <a href="topic_list">Home</a> |    <a href="${ctx}/reg.jsp">Reg</a> |    <c:choose>        <c:when test="${empty loginUser}">            <a href="user_loginUI">Login</a>        </c:when>        <c:otherwise>        You are logged in as ${loginUser.username} - <a href="user_logout">Logout</a>        </c:otherwise>    </c:choose>    ]</center><p /><pre name="code" class="html">



 
<%@ page contentType="text/html; charset=UTF-8"%><%@ include file="/commons/header.jsp"%><%@ taglib uri="/struts-tags" prefix="s"%><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><h2>Response List Page</h2><p><table width="100%" border="1"><tr><td><b>Author</b></td><td><b>Content</b></td><td><b>Status</b></td><td><b>Operation</b></td></tr><!-- topic.responses --><c:forEach items="${resList}" var="theResponse"></c:forEach>// resList 是ResponseAction的属性。提供了getter、setter方法<s:iterator value="resList" var="theResponse"><tr><td>// 对于action对象中的属性,可以直接读取,域中的需要 # 读取<s:property value="user.userName"/></td><td>${content}${theResponse.content} <s:property value="content"/>  <s:property value="#theResponse.content"/>  </td><td> ${theResponse.status==1?"生效":"删除"}<s:property value="#theResponse.status==1?'hh':'jj'"/>  </td><td> <s:if test="#theResponse.status==1">  <a href="response!updateStatus.action?method=remove&res.id=${theResponse.id}">remove </a> </s:if>  <s:if test="#theResponse.status==0">  <a href="response!updateStatus.action?method=rollback&res.id=${theResponse.id}">rollback </a> </s:if> <c:if test="${theResponse.status==0 }"><a href="response!updateStatus.action?method=remove&res.id=${theResponse.id}">remove </a></c:if><c:if test="${theResponse.status==1 }"> <a href="response!updateStatus.action?method=rollback&res.id=${theResponse.id}">rollback </a></c:if><c:choose><c:when test="${theResponse.deleted == true}"><td><a href="${ctx}/topic.do?method=rollback&id=${theResponse.id}">rollback </a></td></c:when><c:otherwise><td><a href="${ctx}/topic.do?method=remove&id=${theResponse.id}">remove </a></td></c:otherwise></c:choose></td> </tr></s:iterator><%-- <c:forEach items="${sessionScope.topic.responses}" var="theResponse"><tr><td>${user.name}// el表达式会先从request中找,如果从request范围没有找到属性值,即从ValueStack中查找对象的属性值  ${theResponse.user.name}// 所以这两种方式都是可以的</td><td>${theResponse.content}</td><td> ${theResponse.status==1?"生效":"删除"} </td><c:choose><c:when test="${theResponse.deleted == true}"><td><a href="${ctx}/topic.do?method=rollback&id=${theResponse.id}">rollback </a></td></c:when><c:otherwise><td><a href="${ctx}/topic.do?method=remove&id=${theResponse.id}">remove </a></td></c:otherwise></c:choose></tr></c:forEach> --%></table><p /><center>[<a href="response!addUI.action">create response</a>]</center><%@ include file="/commons/footer.jsp"%>

0 0
原创粉丝点击