<c:if test="${empty pageFinder.data }"> <tr><td colspan=13 align="center” height="25"xfont color="red"没有查询到相关记录</f</c:if> <s:iterator value="${pageFinder.data}" var="rehs” status="status"><s:set var="index”value="#status getIndex()"/> 0 <tr> <td> <input id-"rulesId <s:property value="#rehs[o]” />” name="chkItem"value="<s:property value="#rehs[@]” />” type="checkbox"”onclick="itemCheckbox changed();” /> </td>这段代码为什么${pageFinder.data}会报不识别这个${}标签错误?
时间: 2023-10-14 09:06:21 浏览: 38
这段代码看起来是JSP页面中的代码,${pageFinder.data}是一个EL表达式,用于获取pageFinder对象中的data属性的值,但是可能因为EL表达式没有被正确解析而导致报错。可能需要检查JSP页面中是否有正确引入taglib库,以及是否在web.xml中正确配置了JSP servlet。
相关问题
在struts2 2.3.15.1版本中将jsp页面中的<c:if test="${empty pageFinder.data }"> <tr><td colspan=13 align="center” height="25"xfont color="red"没有查询到相关记录</f</c:if> <s:iterator value="%{pageFinder.data}" var="rehs” status="status"><s:set var="index”value="#status getIndex()"/> 这段代码中的<s:iterator value="%{pageFinder.data}"改为<s:iterator value="${pageFinder.data}"系统会报does not accept any expressions这个错误,是什么原因?
在Struts2中,当使用`${}`表达式时,它会被解析为OGNL表达式,而非JSP表达式。而在JSP页面中使用的`<c:if>`标签和`<s:iterator>`标签是JSTL标签和Struts2标签,它们并不支持OGNL表达式。因此,将`<s:iterator>`标签中的`%{}`改为`${}`会导致系统报错。正确的做法是保留`%{}`。
<form action="SelectNews" method="post"> 请输入查询条件:<input type="text" name="key"> <input type="submit" value="查询"> </form><br> <table border="1" width="70%" cellpadding="0" cellspacing="0"> <tr align="center"> <td>编号</td> <td>标题</td> <td>类型</td> <td>发布人</td> <td>发布日期</td> <td>状态</td> <td>是否头条</td> <td colspan="4">操作</td> </tr> <c:forEach items="${newsList }" var="news"> <tr align="center"> <td>${news.nid }</td> <td>${news.title }</td> <td>${news.type }</td> <td>${news.userName }</td> <td>${news.pubtime }</td> <td> <c:choose> <c:when test="${news.state==0 }">待审核</c:when> <c:when test="${news.state==1 }">通过</c:when> <c:otherwise>未通过</c:otherwise> </c:choose> </td> <td> <c:choose> <c:when test="${news.top==0 }">否</c:when> <c:otherwise>是</c:otherwise> </c:choose> </td> <td>${news.top==0?"是":"否" }</td> <td> <a href="NewsDetail?nid=${news.nid }&op=show">查看</a> <a href="NewsDetail?nid=${news.nid }&op=update">修改</a> <c:if test="${user.rule==0 }"> <a href="newsDelete.jsp?nid=${news.nid }"> 删除</a> </c:if> <c:if test="${user.rule==0 }"> 审核</c:if> </td> </tr> </c:forEach> </table>这是前端代码如何优化为上文你所陈述的代码
好的,为了实现批量删除,我们需要将前端页面中的删除按钮改为复选框,并在表单中添加一个提交按钮。同时,我们还需要给每个复选框设置一个value属性,用于存储对应新闻的ID。修改后的代码如下:
```html
<form action="batchDeleteNews" method="post">
请输入查询条件:<input type="text" name="key">
<input type="submit" value="查询"><br><br>
<table border="1" width="70%" cellpadding="0" cellspacing="0">
<tr align="center">
<td>选择</td>
<td>编号</td>
<td>标题</td>
<td>类型</td>
<td>发布人</td>
<td>发布日期</td>
<td>状态</td>
<td>是否头条</td>
<td colspan="4">操作</td>
</tr>
<c:forEach items="${newsList}" var="news">
<tr align="center">
<td><input type="checkbox" name="newsIds" value="${news.nid}"></td>
<td>${news.nid}</td>
<td>${news.title}</td>
<td>${news.type}</td>
<td>${news.userName}</td>
<td>${news.pubtime}</td>
<td>
<c:choose>
<c:when test="${news.state==0 }">待审核</c:when>
<c:when test="${news.state==1 }">通过</c:when>
<c:otherwise>未通过</c:otherwise>
</c:choose>
</td>
<td>
<c:choose>
<c:when test="${news.top==0 }">否</c:when>
<c:otherwise>是</c:otherwise>
</c:choose>
</td>
<td>${news.top==0?"是":"否"}</td>
<td>
<a href="NewsDetail?nid=${news.nid}&op=show">查看</a>
<a href="NewsDetail?nid=${news.nid}&op=update">修改</a>
<c:if test="${user.rule==0}">
<a href="javascript:void(0);" onclick="deleteNews(${news.nid})"> 删除</a>
</c:if>
<c:if test="${user.rule==0}"> 审核</c:if>
</td>
</tr>
</c:forEach>
</table>
<button type="submit">批量删除</button>
</form>
```
上面的代码中,我们给复选框设置了name属性为"newsIds",并将对应的新闻ID作为value值传递到后端。在表格的最后,我们添加了一个提交按钮,用于提交批量删除的请求。同时,我们还将原来的删除按钮改为了一个超链接,点击时会执行一个JavaScript函数,用于删除单个新闻。
相关推荐
给下面代码增加分页功能,要求细致,逻辑清楚,<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"> <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的用户才能看见批量删除的按钮
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<body>
<input type="button" value="新增" onclick="add()">
ID
姓名
年龄
密码
修改 删除
<c:if test="${not empty list }">
<c:forEach items="${list }" var="user" varStatus="s">
${s.count}
${user.username}
${user.age}
${user.password}
修改
删除
</c:forEach>
</c:if>
<script >function add(){
location.href="add.jsp";
}
function updatemethod(userid) {
var id = parseInt('<%= session.getAttribute("id") %>');
if (userid != id) {
alert("你不能修改别人的信息");
} else {
window.location.href = "update.jsp";
}
}
function deletemethod(userid) {
var id = parseInt('<%= session.getAttribute("id") %>');
if (userid != id) {
alert("你不能删除别人的信息");
} else {
if(confirm("你确定要删除自己的信息吗?")) {
window.location.href = "index.jsp";
}
}
}</script>
</body>
</html>上述代码哪里报错,要如何修改
修改这段代码 首页 上一页 下一页 最后一页
跳转到: <input id="pageNo" type="text" class="form-control form1" name="pageNo" value="${list.pageNo}" /> 每页记录数: <input class="form-control form1" type="text" name="pageCount" value="${list.pageCount}" /> <input class="btn btn-primary" type="submit" value="跳转" /> 共有 ${list.totalPage} 页
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>人力资源管理系统</title> <meta http-equiv="Content-Type" content="text/html; charset=GBK"> </head> <body> 人才信息 姓名 性别 年龄 职位 所学专业 工作经验 执行操作 we33 男 0 ew we ew 详细 删除 ds 女 0 ds ds ds 详细 删除 李四 男 36 JAVA架构师 计算机 5年 详细 删除 王五 男 28 软件测试工程师 计算机 三年 详细 删除 </body> </html>实现后端代码
新闻发布系统>>新闻管理>>查询新闻 <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的用户才能看见批量删除的按钮
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<body>
<input type="button" value="新增" onclick="add()">
ID
姓名
年龄
密码
修改 删除
<c:if test="${not empty list }">
<c:forEach items="${list }" var="user" varStatus="s">
${s.count}
${user.username}
${user.age}
${user.password}
修改
删除
</c:forEach>
</c:if>
<script >function add(){
location.href="add.jsp";
}
function updatemethod(userid) {
var id = parseInt('<%= session.getAttribute("id") %>');
if (userid != id) {
alert("你不能修改别人的信息");
} else {
window.location.href = "update.jsp";
}
}
function deletemethod(userid) {
var id = parseInt('<%= session.getAttribute("id") %>');
if (userid != id) {
alert("你不能删除别人的信息");
} else {
if(confirm("你确定要删除自己的信息吗?")) {
window.location.href = "index.jsp";
}
}
}</script>
</body>
</html>上述代码哪里报错,要如何修改
修改这段代码 首页 上一页 下一页 最后一页
跳转到: <input id="pageNo" type="text" class="form-control form1" name="pageNo" value="${list.pageNo}" /> 每页记录数: <input class="form-control form1" type="text" name="pageCount" value="${list.pageCount}" /> <input class="btn btn-primary" type="submit" value="跳转" /> 共有 ${list.totalPage} 页
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>人力资源管理系统</title> <meta http-equiv="Content-Type" content="text/html; charset=GBK"> </head> <body> 人才信息 姓名 性别 年龄 职位 所学专业 工作经验 执行操作 we33 男 0 ew we ew 详细 删除 ds 女 0 ds ds ds 详细 删除 李四 男 36 JAVA架构师 计算机 5年 详细 删除 王五 男 28 软件测试工程师 计算机 三年 详细 删除 </body> </html>实现后端代码
修改这段代码 首页 上一页 下一页 最后一页
跳转到: <input id="pageNo" type="text" class="form-control form1" name="pageNo" value="${list.pageNo}" /> 每页记录数: <input class="form-control form1" type="text" name="pageCount" value="${list.pageCount}" /> <input class="btn btn-primary" type="submit" value="跳转" /> 共有 ${list.totalPage} 页
跳转到: <input id="pageNo" type="text" class="form-control form1" name="pageNo" value="${list.pageNo}" /> 每页记录数: <input class="form-control form1" type="text" name="pageCount" value="${list.pageCount}" /> <input class="btn btn-primary" type="submit" value="跳转" /> 共有 ${list.totalPage} 页