el 表达式问题这里是jsp文件里的服务器端脚本。 整个程序是struts架构 ,现在想把以下的代码换成el表达式 <%
List<Record> alist=(List<Record>)request.getAttribute("alist");
if(alist != null && alist.size()>0)
{
out.println("<table border=\"2\" cellspacing=\"0\" cellpadding=\"0\">");
out.println("<tr>");
out.println("<th BGCOLOR=\"#00FF00\"><b>id</b></th>");
out.println("<td BGCOLOR=\"#00FF00\"><b><a href=User.do?act=2&sort=Score>Score</b></td>");
out.println("<td BGCOLOR=\"#00FF00\"><b><a href=User.do?act=2&sort=UserName>UserID</b></td>");
out.println("</tr>");
int j;
int id1;
String fullname;
String firstName;
String secondName;
for(int i=0;i<alist.size();i++)
{
Record bean=(Record)alist.get(i);
out.println("<tr>");
j=i+1;
fullname=bean.getFullName();
firstName=bean.getFirstName();
secondName=bean.getSecondName(); out.println("<td class=text>"+j+ "</td>" );
out.println("<td class=text>"+ bean.getScore() + "</td>");
out.println("<td class=text>"+ bean.getUserName() + "</td>");
out.println("<td class=text>"+ firstName + "</td>");
out.println("<td class=text>"+ secondName + "</td>");
}我的架构是 action里处理业务逻辑
(List<Record>)request.getAttribute("alist");
这个事情是绝对可以做的
(第一句可以参考 c:if test="${fn:length(myActionForm.containerMap.aList) > 0}">
<script>
var betProfitVar='${myActionForm.containerMap.firstName}';)
while 可以 被<c:forEach var="myBean" items="${myActionForm.containerMap.aList}" varStatus="stat"> 替换
for(int i=0;i<alist.size();i++)
可以被 c:if 《/c:if》--替换 这里不是很清晰
这些代码半懂不懂,有思路但不是很精确
不知道这里如何被完整的将上面的代码替换。 希望熟悉el的结合上面的代码分析如何解决
List<Record> alist=(List<Record>)request.getAttribute("alist");
if(alist != null && alist.size()>0)
{
out.println("<table border=\"2\" cellspacing=\"0\" cellpadding=\"0\">");
out.println("<tr>");
out.println("<th BGCOLOR=\"#00FF00\"><b>id</b></th>");
out.println("<td BGCOLOR=\"#00FF00\"><b><a href=User.do?act=2&sort=Score>Score</b></td>");
out.println("<td BGCOLOR=\"#00FF00\"><b><a href=User.do?act=2&sort=UserName>UserID</b></td>");
out.println("</tr>");
int j;
int id1;
String fullname;
String firstName;
String secondName;
for(int i=0;i<alist.size();i++)
{
Record bean=(Record)alist.get(i);
out.println("<tr>");
j=i+1;
fullname=bean.getFullName();
firstName=bean.getFirstName();
secondName=bean.getSecondName(); out.println("<td class=text>"+j+ "</td>" );
out.println("<td class=text>"+ bean.getScore() + "</td>");
out.println("<td class=text>"+ bean.getUserName() + "</td>");
out.println("<td class=text>"+ firstName + "</td>");
out.println("<td class=text>"+ secondName + "</td>");
}我的架构是 action里处理业务逻辑
(List<Record>)request.getAttribute("alist");
这个事情是绝对可以做的
(第一句可以参考 c:if test="${fn:length(myActionForm.containerMap.aList) > 0}">
<script>
var betProfitVar='${myActionForm.containerMap.firstName}';)
while 可以 被<c:forEach var="myBean" items="${myActionForm.containerMap.aList}" varStatus="stat"> 替换
for(int i=0;i<alist.size();i++)
可以被 c:if 《/c:if》--替换 这里不是很清晰
这些代码半懂不懂,有思路但不是很精确
不知道这里如何被完整的将上面的代码替换。 希望熟悉el的结合上面的代码分析如何解决
解决方案 »
- 关于线程的开启跟关闭。。
- 时钟 定时刷新界面 求教
- 请问:如何查看java程序编译和执行过程啊?
- 用JAVA 如何获取硬盘 序列号
- 求救,Integer.toString(8,3)是什么意思?看了api,不懂?
- 内部类如何实例化
- 请问eclipse有什么好的调试器插件能监视一个变量,当这个变量在被改变之前先挂断,然后自动转到修改这个变量的代码处?
- 用POI操作EXCEL的问题
- 数据库连接问题
- DriverManager.getConnection()每次获取连接的时候都要几秒钟
- Thread.sleep()在监听器里的怪事
- 关于日期类型java.sql.Date存储到数据库sql server中的异常,大家帮忙解决一下
如果一般的input , jsp可以用 el表达式 $(param.yourinput)来解决
现在一个复杂的对象List <Record》 (record还是一个类 也就是一个对象链表)
List <Record> alist=(List <Record>)request.getAttribute("alist"); ----这个请问该如何来转化,很头疼,可否直接$(param.alist)????(如果不可以为什么?)
<table border="2" cellspacing="0" cellpadding="0">
<tr>
<th BGCOLOR="#00FF00"> <b>id </b> </th>
<td BGCOLOR="#00FF00"> <b> <a href=User.do?act=2&sort=Score>Score </b> </td>
<td BGCOLOR="#00FF00"> <b> <a href=User.do?act=2&sort=UserName>UserID </b> </td>
</tr>
<c:forEach var="myBean" items="${aList}">
<tr>
<td class=text>${myBean.score}</td>
<td class=text>${myBean.username}</td>
<td class=text>${myBean.firstName}</td>
<td class=text>${myBean.secondName}</td>
</tr>
</c:forEach>
</table>
</c:if>
<a href=User.do?act=1&firstName="+java.net.URLEncoder.encode(firstName)+"&secondName="+java.net.URLEncoder.encode(secondName)+"&birthday="+java.net.URLEncoder.encode(birthday)------这里如何转换
${myBean.secondName} </td> 之前是服务器端脚本《%。。%》所以可以用java.net.URLEncoder.encode函数
1现在是客户端脚本 这里不知道该如何转化(需要找到对应的.encode函数
2<a href=User.do?act=1&firstName="+ ${myBean.firstName}+。--请问可以这样用吗?)
<tr>
<td class=text>${myBean.score} </td>
<td class=text>${myBean.username} </td>
<td class=text>${myBean.firstName} </td>
<td class=text>${myBean.secondName} </td>
</tr>
</c:forEach>
<c:url var="test" value="www.baidu.com">
<c:param name="id" value="3"></c:param>
<c:param name="name" value="张三"></c:param>
</c:url>
<c:out value="${test}"></c:out>
<c:forEach var="myBean" items="${aList}">
<tr>
现在要加入行号如 --- <td class=text>"+j+ " </td>" ==这里如何用el表达
<td class=text>${myBean.score} </td>
<td class=text>${myBean.username} </td>
<td class=text>${myBean.firstName} </td>
<td class=text>${myBean.secondName} </td>
</tr>
</c:forEach>
原来的代码请参考 <td class=text>"+j+ " </td>" ); 如何在el表达式里写?
for(int i=0;i <alist.size();i++)
{
Record bean=(Record)alist.get(i);
out.println(" <tr>");
j=i+1;
fullname=bean.getFullName();
firstName=bean.getFirstName();
secondName=bean.getSecondName(); out.println(" <td class=text>"+j+ " </td>" );
下面el表达式
c:if test="${alist!=null}">
<table border="2" cellspacing="0" cellpadding="0">
<tr>
<th BGCOLOR="#00FF00"> <b>id </b> </th>
<td BGCOLOR="#00FF00"> <b> <a href=User.do?act=2&sort=Score>Score </b> </td>
<td BGCOLOR="#00FF00"> <b> <a href=User.do?act=2&sort=UserName>UserID </b> </td>
</tr>
<c:forEach var="myBean" items="${aList}">
<tr>
<td class=text>${myBean.score} </td>
<td class=text>${myBean.username} </td>
<td class=text>${myBean.firstName} </td>
<td class=text>${myBean.secondName} </td>
</tr>
</c:forEach>
</table>
</c:if>jsp页面上的标题 <td BGCOLOR="#00FF00"> <b> <a href=User.do?act=2&sort=Score>Score </b> </td>
<td BGCOLOR="#00FF00"> <b> <a href=User.do?act=2&sort=UserName>UserID </b> </td>
</
能出来, 但是没有数据 。 (实际上是有很多的数据的)
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql_rt" %>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<html>
<head>
<title>使用SQL标签</title>
</head><body bgcolor="white">
<c:set var="noOfRows" value="10" />
<sql:setDataSource driver =
"sun.jdbc.odbc.JdbcOdbcDriver" url =
"jdbc:odbc:accp" user="sa" password="" var="conn"/>
<c:if test="${custList == null}">
<sql:query var="custList" scope="session"
sql="SELECT * FROM employee ORDER BY LName"
dataSource="${conn}"/>
</c:if>
<c:choose>
<c:when test="${custList.rowCount == 0}">
此处不再有其他客户...
</c:when>
<c:otherwise>
<b>以下是客户列表:</b>
<p>
<table border="1">
<th>姓氏</th>
<th>名字</th>
<th>年龄</th>
<c:forEach items="${custList.rows}" var="row"
begin="${param.start}" end="${param.start +
noOfRows - 1}">
<tr>
<td><c:out value="${row.LName}" /></td>
<td><c:out value="${row.FName}" /></td>
<td><c:out value="${row.job_id}" /></td>
</tr>
</c:forEach>
</table>
</c:otherwise>
</c:choose>
<p>
<c:choose>
<c:when test="${param.start > 0}">
<a href="foreachexample.jsp?start=<c:out
value="${param.start - noOfRows}" />">
上一页</a>
</c:when>
<c:otherwise>
上一页
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${param.start + noOfRows <
custList.rowCount}">
<a href="foreachexample.jsp?start=<c:out
value="${param.start + noOfRows}" />">
下一页</a>
</c:when>
<c:otherwise>
下一页
</c:otherwise>
</c:choose>
共${custList.rowCount}条记录
共 <fmt:formatNumber type="number" value="${custList.rowCount%noOfRows==0?custList.rowCount/noOfRows:(custList.rowCount%noOfRows>4?(custList.rowCount/noOfRows):(custList.rowCount/noOfRows+1))}" maxFractionDigits="0"/> 页 第 <fmt:formatNumber type="number" value="${(param.start%noOfRows==0?param.start/noOfRows:(param.start%noOfRows>4?(param.start/noOfRows):(param.start/noOfRows+1)))+1}" maxFractionDigits="0"/> 页
</body>
</html>说明:这里使用到了标准标签库中SQL标签去查询数据记录。使用条件标签判断分页中上下页的是否链接。使用EL表达式显示总记录数,<c:set var="noOfRows" value="10" />用来设置每页的显示记录数。通过总记录数和每页记录数来计算总页数。因为EL表达式中‘/’结果是实际的浮点数,而不是整除,也没有函数来完成取整,这里就结合格式化标签<fmt:formatNumber type="number" value="${custList.rowCount%noOfRows==0?custList.rowCount/noOfRows:(custList.rowCount%noOfRows>4?(custList.rowCount/noOfRows):(custList.rowCount/noOfRows+1))}" maxFractionDigits="0"/>来完成格式化取整,maxFractionDigits="0"表示保留0位小数,即取整,但是这的取整也只是四舍五入,所以又给计算页数带来困难,最后我通过${custList.rowCount%noOfRows==0?custList.rowCount/noOfRows: (custList.rowCount%noOfRows>4?(custList.rowCount/noOfRows): (custList.rowCount/noOfRows+1))}两个条件表达式嵌套完成页数计算用同样的方法实现计算第几页的目的