|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
再举这样一个例子:如果你想对一个数字取绝对值,你会怎么做呢?java的做法是intc=Math.abs(-166);而ruby的做法是:c=-166.abs。呵呵,这就看出了java与ruby的区别。
用于办理Action中request.setAttribute("list",list)
因为我用的是struts框架,就拿全部项目先容:
1.起首把jstl的两个经常使用包jstl.jar、standard.jar加载到情况中
2.Action代码:(全部历程不必要懂得,这儿办法就是前往一个封装Students对象的list,然后request.setAttribute("list",list)起来)
publicActionForward selectStudent(ActionMapping mapping,ActionFormform,
HttpServletRequest request,HttpServletResponse response) {
StudentForm studentForm = (StudentForm) form;
DBConnection dbconn = new DBConnection();
Connection conn = dbconn.getConnection();
StudentServiceFactory serviceFactory = new StudentServiceFactory();
List list = serviceFactory.getStudentService().selectStudent(conn);
request.setAttribute("list",list);
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return mapping.findForward("show");
}
3.show.jsp页面:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>//这三句很主要
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP show.jsp starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/CSS" href="styles.css">
-->
</head>
<body>
查询了局以下:<br>
<table>
<tr>
<td>ID</td>
<td>姓名</td>
</tr>
<c:forEach items="${list}" var="student">// items为list的一个迭代器,list为Action中传送过去的list,student为Student类对象
<tr>
<td>${student.id }</td>//输入student的id属性
<td>${student.name }</td>//输入student的name属性
</tr>
</c:forEach>
<logic:iterate id="li" name="list" type="vo.Student">//id为自界说的名字,name为Action中传过去的list,type为实体类,包含完全路径,这里是vo.Student
<tr>
<td><bean:write name="li" property="id"/></td>//name为逻辑名,和logic:iterate id="li"中的id对应,property为实体类中真实的属性
<td><bean:write name="li" property="name"/></td>
<td><a href="student.do?method=deleteStudent&id=<bean:write name="li" property="id"/>">删除</a></td>
</tr>
</logic:iterate>
</table>
<a href="student.jsp">前往</a>
</body>
</html>
在JSP页面引进Struts标签库的时分有所分歧:
struts1.3的为:
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>大概<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
先谈谈我对java的一些认识。我选择java,是因为他语法简单,功能强大,从web,到桌面,到嵌入式,无所不能。但当我进一步了解了java后,感叹,java原来也有许多缺点。 |
|