操作成功 <c:choose> <c:when test="${news.rule==0 }"><a href="index.jsp">返回</a></c:when> <c:otherwise><a href="index2.jsp"></c:otherwise> </c:choose>修改这段代码使通过不同rule访问到不同的index页面
时间: 2023-08-14 18:21:14 浏览: 125
可以使用多个<c:when>标签来实现不同规则对应不同的页面,修改后的代码如下:
```html
<c:choose>
<c:when test="${news.rule==0}">
<a href="index.jsp">返回</a>
</c:when>
<c:when test="${news.rule==1}">
<a href="index1.jsp">返回</a>
</c:when>
<c:when test="${news.rule==2}">
<a href="index2.jsp">返回</a>
</c:when>
<c:otherwise>
<a href="index3.jsp">返回</a>
</c:otherwise>
</c:choose>
```
在这个例子中,当${news.rule}的值为0时,跳转到index.jsp页面;当值为1时,跳转到index1.jsp页面;当值为2时,跳转到index2.jsp页面;否则跳转到index3.jsp页面。
相关问题
<%@ page import="java.util.List" %> <%@ page import="com.example.model.User" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <title>Title</title> <h1>User List</h1> <table border="1"> <tr> <td><strong>Id</strong></td> <td><strong>Username</strong></td> <td><strong>password</strong></td> <td><strong>Email</strong></td> <td><strong>Gender</strong></td> <td><strong>Birthday</strong></td> </tr> <c:choose> <c:when test="${empty userlist}"> <tr><td> <h1>No Order Found.</h1> </td> </c:when> <c:otherwise> <c:forEach var="u" items="${userlist}"> <tr> <td>User :<span><%=u.getUsername()%></span></td> <td>Password :<span><%=u.getPassword()%></span></td> <td>Email :<span><%=u.getEmail()%></span></td> <td>Sex :<span><%=u.getSex()%></span></td> <td>Country :<span><%=u.getCountry()%></span></td> <td> <a href="edit?id=<%=u.getId()%>">Edit</a></td> <td> <a href="delete?id=<%=u.getId()%>">Delete</a></td> </tr> </c:forEach> </c:otherwise> </c:choose> </table> <a href="register">Add User</a>
这是一个 JSP 页面,用于显示用户列表。它引入了 Java 类型的 List 和 User,以及 JSTL 的核心标签库。它通过使用 forEach 标签遍历 userlist 中的用户对象,并显示它们的用户名、密码、电子邮件、性别和国家。如果用户列表为空,则显示“找不到订单”的消息。此外,页面还提供了“添加用户”链接,指向“register”页面。
<div class="context_menu"> <ul <c:choose><c:when test="${requestScope.searchValue != null}"> data-value="${requestScope.searchValue}"</c:when> <c:otherwise>data-type = ${requestScope.searchType}</c:otherwise></c:choose>> <li data-name="product_name" <c:if test="${requestScope.orderBy =='product_name' || requestScope.orderBy ==null}">class="orderBySelect"</c:if>> <span>综合</span> <span class="orderByAsc"></span> </li> <li data-name="product_create_date" <c:if test="${requestScope.orderBy =='product_create_date'}">class="orderBySelect"</c:if>> <span>新品</span> <span class="orderByAsc"></span> </li> <li data-name="product_sale_count" <c:if test="${requestScope.orderBy =='product_sale_count'}">class="orderBySelect"</c:if>> <span>销量</span> <span class="orderByAsc"></span> </li> <li data-name="product_sale_price" <c:if test="${requestScope.orderBy =='product_sale_price'}">class="orderBySelect"</c:if>> <span style="position: relative;left: 3px">价格</span> <span class="orderByDesc <c:if test="${requestScope.isDesc == true}">orderBySelect</c:if>" style="bottom: 5px; left: 6px;"></span> <span class="orderByAsc <c:if test="${requestScope.isDesc == false}">orderBySelect</c:if>" style="top:4px;right: 5px;"></span> </li> </ul> </div>
这段代码是一个包含排序选项的菜单,其中有四个选项:综合、新品、销量和价格。它们被包含在一个无序列表中,每个选项都有一个"data-name"属性,表示该选项对应的数据属性,同时也有一个"class"属性,表示当前被选中的选项。此外,价格选项还有两个子元素,表示升序和降序排序。整个菜单是用HTML和JSP标签库编写的。
阅读全文
相关推荐





新闻发布系统>>新闻管理>>查询新闻 <form action="SelectNews" method="post"> 请输入查询条件:<input type="text" name="key"> <input type="submit" value="查询"> </form>
编号 标题 类型 发布人 发布日期 状态 是否头条 操作 <c:forEach items="${newsList }" var="news"> <input type="checkbox" name="newsIds" value="${news.nid}"> ${news.nid } ${news.title } ${news.type } ${news.userName } ${news.pubtime } <c:choose> <c:when test="${news.state==0 }">待审核</c:when> <c:when test="${news.state==1 }">通过</c:when> <c:otherwise>未通过</c:otherwise> </c:choose> <c:choose> <c:when test="${news.top==0 }">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> ${news.top==0?"是":"否" } 查看 <c:if test="${user.rule==0 || user.uid ==news.uid }"> 修改 </c:if> <c:if test="${user.rule==0 }"> 删除 </c:if> <c:if test="${user.rule==0 }"> 审核</c:if> </c:forEach> <button type="button" >批量删除</button> </body> <script type="text/javascript"> function banchDelete(){ var idsArray = document.getElementsByName("newsIds"); var nidArray=[]; for(k in idsArray){ if(idsArray[k].checked){ nidArray.push(idsArray[k].value); } } if(nidArray.length==0){ alert("请选择要删除的新闻"); return } window.location.href="./newsBanchDelete.jsp?nids="+nidArray.join(","); } </script>这段代码优化使user.rule=0的用户才能看见批量删除的按钮





给下面代码增加分页功能,要求细致,逻辑清楚,<form action="./../selectNews" method="post"> <input type="text" name="key" id="key" placeholder="请输入标题"/> <input type="submit" value="查询"/> 发布新闻 返回主页 </form> 新闻编号 新闻标题 <%-- 新闻内容 --%> 新闻类别 发布人 发布时间 状态 是否头条 操作 <c:forEach items="${newslist}" var="u"> ${u.nid} ${u.title} <%-- ${u.content} --%> ${u.type} ${u.userName} ${u.pubTime} <c:choose> <c:when test="${u.state==0}">未审核</c:when> <c:when test="${u.state==1}">审核通过</c:when> <c:otherwise>未通过</c:otherwise> </c:choose> <c:choose> <c:when test="${u.top==0}">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> <c:choose> <c:when test="${user.rule==1}"> 查看 修改 删除 审核 </c:when> <c:when test="${user.rule==0 && user.uid==u.uid}"> 查看 修改 删除 </c:when> <c:otherwise> 查看 </c:otherwise> </c:choose> </c:forEach>
<form action="SelectNews" method="post"> 请输入查询条件:<input type="text" name="key"> <input type="submit" value="查询"> </form>
编号 标题 类型 发布人 发布日期 状态 是否头条 操作 <c:forEach items="${newsList }" var="news"> ${news.nid } ${news.title } ${news.type } ${news.userName } ${news.pubtime } <c:choose> <c:when test="${news.state==0 }">待审核</c:when> <c:when test="${news.state==1 }">通过</c:when> <c:otherwise>未通过</c:otherwise> </c:choose> <c:choose> <c:when test="${news.top==0 }">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> ${news.top==0?"是":"否" } 查看 修改 <c:if test="${user.rule==0 }"> 删除 </c:if> <c:if test="${user.rule==0 }"> 审核</c:if> </c:forEach> 这是前端代码如何优化为上文你所陈述的代码



<form action="SelectNews" method="post"> 请输入查询条件:<input type="text" name="key"> <input type="submit" value="查询"> </form>
编号 标题 类型 发布人 发布日期 状态 是否头条 操作 <c:forEach items="${newsList }" var="news"> ${news.nid } ${news.title } ${news.type } ${news.userName } ${news.pubtime } <c:choose> <c:when test="${news.state==0 }">待审核</c:when> <c:when test="${news.state==1 }">通过</c:when> <c:otherwise>未通过</c:otherwise> </c:choose> <c:choose> <c:when test="${news.top==0 }">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> ${news.top==0?"是":"否" } 查看 修改 <c:if test="${user.rule==0 }"> 删除 </c:if> <c:if test="${user.rule==0 }"> 审核</c:if> </c:forEach> 这是前端代码如何优化为上文你所陈述的代码



