社区
Web 开发
帖子详情
求助!高分相送~
saviourlee
2003-05-25 11:07:38
我在做一个考试系统。老师的要求是每个页面显示一道选择题。那20道题岂不要20个jsp页面? 有没有简单一点的办法?
btw: 老师还要求能回到原来的所选择的答案(cookie)
要是哪位大侠有参考代码就更佳!
我的email: saviour_2001@163.com
多谢!
望不吝赐教!
...全文
39
5
打赏
收藏
求助!高分相送~
我在做一个考试系统。老师的要求是每个页面显示一道选择题。那20道题岂不要20个jsp页面? 有没有简单一点的办法? btw: 老师还要求能回到原来的所选择的答案(cookie) 要是哪位大侠有参考代码就更佳! 我的email: saviour_2001@163.com 多谢! 望不吝赐教!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
flystar326
2003-05-26
打赏
举报
回复
不需要20个页面了,我觉得可以参照分页的做法
leshui
2003-05-26
打赏
举报
回复
分页就可以了
只要是有规律的东西
都可以用循环来做
asdmonster
2003-05-26
打赏
举报
回复
怎么现在流行要代码?
satyrping
2003-05-26
打赏
举报
回复
看这个例子,肯定对你又帮助
productList.jsp :
<!-- JSP Directives -->
<%@ page errorPage="myError.jsp?from=productList.jsp"
%>
<html>
<head>
<title>Product List</title>
</head>
<body>
<basefont face="Arial">
<jsp:useBean id="pBean" scope="session" class="bean.ProductBean"/>
<!-- Build table of products -->
<table align="center" width="600">
<tr>
<td width="20%"><b>Product ID</b></td>
<td width="30%"><b>Description</b></td>
<td width="35%"><b>Manufacturer</b></td>
<td width="15%"><b>Price</b></td>
</tr>
<%
int rowCount = 0;
int startRow = 0;
if (pBean.populate()) {
String start = (String) request.getParameter("start");
if (start != null) {
startRow = new Integer(start).intValue();
pBean.setStartRow(startRow);
}
while (rowCount < 10 && pBean.nextRow() > 0) {
rowCount++;
%>
<tr>
<td width="20%"><jsp:getProperty name="pBean" property="prodID"/></td>
<td width="30%"><jsp:getProperty name="pBean" property="prodDesc"/></td>
<td width="35%"><jsp:getProperty name="pBean" property="prodManuf"/></td>
<td width="15%"><jsp:getProperty name="pBean" property="prodPrice"/></td>
</tr>
<%
}
}
%>
<!-- Display the back and next links -->
<tr>
<td colspan="2" align="center">
<br><a href="?start=<%= (startRow > 9) ? startRow - 10 : 0%>">Back</a>
</td>
<td colspan="2" align="center">
<br><a href="?start=<%= pBean.getCurrentRow() %>">Next</a>
</td>
</tr>
</table>
</body>
</html>
ProductBean.java :
package bean;
import java.util.*;
import java.sql.*;
public class ProductBean implements java.io.Serializable {
/* Member Variables */
private String prodID;
private String prodDesc;
private String prodManuf;
private float prodPrice;
/* ArrayLists to hold recordsets */
private List prodIDList, prodDescList, prodManufList, prodPriceList;
/* Helper Variables */
private int currentRow;
private int rowCount;
private Connection db = null;
/* Constructor */
public ProductBean() {
/* Initialize bean properties */
setProdID("");
setProdDesc("");
setProdManuf("");
setProdPrice(0.00f);
/* Initialize arrayLists to hold recordsets */
prodIDList = new ArrayList();
prodDescList = new ArrayList();
prodManufList = new ArrayList();
prodPriceList = new ArrayList();
/* Initialize helper variables */
currentRow = 0;
rowCount = 0;
/* Get database connection */
dbConnect();
}
/* Get Database Connection */
private void dbConnect() {
if (db == null) {
try {
Class.forName("org.gjt.mm.mysql.Driver");
db = DriverManager.getConnection("jdbc:mysql://localhost:3306/catalog","root","appleping");
}
catch (Exception e) {
System.out.println("Error Connecting to catalog DB: "+ e.toString());
}
}
}
/* Accessor Methods */
public String getProdID() {
return prodID;
}
public void setProdID(String _prodID) {
prodID = _prodID;
}
public String getProdDesc() {
return prodDesc;
}
public void setProdDesc(String _prodDesc) {
prodDesc = _prodDesc;
}
public String getProdManuf() {
return prodManuf;
}
public void setProdManuf(String _prodManuf) {
prodManuf = _prodManuf;
}
public float getProdPrice() {
return prodPrice;
}
public void setProdPrice(float _prodPrice) {
prodPrice = _prodPrice;
}
/* Read-only attribute */
public int getCurrentRow() {
return currentRow;
}
/* Populate Record List */
public boolean populate() {
/* If prodIDList is empty, then execute the query to populate it */
if (prodIDList.isEmpty()) {
try {
/* Execute Query */
Statement s = db.createStatement();
ResultSet rs = s.executeQuery("select * from product");
prodIDList.clear();
prodDescList.clear();
prodManufList.clear();
prodPriceList.clear();
rowCount = 0;
while (rs.next()) {
prodIDList.add(rs.getString("id"));
prodDescList.add(rs.getString("description"));
prodManufList.add(rs.getString("manuf"));
prodPriceList.add((new Float(rs.getFloat("price"))));
rowCount++;
}
}
catch (Exception e) {
System.out.println("Error populating productBean: "+ e.toString());
return false;
}
}
/* Return status of operation (assume success if it made it this far) */
return true;
}
/* Reset current row */
public void setStartRow(int _start) {
if (_start < rowCount) {
currentRow = _start;
}
}
/* Move to next row */
public int nextRow() {
if (currentRow == rowCount) {
currentRow = 0; // Reset for next page request
return 0; // return 0 to indicate end of recordset
}
/* Populate bean properties with current row */
setProdID((String)prodIDList.get(currentRow));
setProdDesc((String)prodDescList.get(currentRow));
setProdManuf((String)prodManufList.get(currentRow));
Float price = (Float)prodPriceList.get(currentRow);
setProdPrice(price.floatValue());
currentRow++;
/* return currentRow*/
return currentRow;
}
}
vidaboy
2003-05-26
打赏
举报
回复
不需要
只需要当点击下一页时,调出下一道题的文本即可以了。
代码暂时没有
单选题 计算机软件一般包括,
求助
,50道计算机试题~求答案
该楼层疑似违规已被系统折叠隐藏此楼查看此楼B. 1.2MBC. 360KBD. 1.44MB23.单选题: CRT显示器采用( )显示方式,因此显示效果好,色彩比较亮丽。A. 模拟B. 电信号C.
高分
辨率D. 数字24.单选题: 在微型计算机内存储器中,不能用指令修改其存储内容的部分是( )。A. DRAMB. ROMC. RAMD. SRAM25.单选题: 主板性能的高低主要由( )芯...
单选题7.微型计算机接口位于,
求助
,50道计算机试题~求答案
该楼层疑似违规已被系统折叠隐藏此楼查看此楼B. 1.2MBC. 360KBD. 1.44MB23.单选题: CRT显示器采用( )显示方式,因此显示效果好,色彩比较亮丽。A. 模拟B. 电信号C.
高分
辨率D. 数字24.单选题: 在微型计算机内存储器中,不能用指令修改其存储内容的部分是( )。A. DRAMB. ROMC. RAMD. SRAM25.单选题: 主板性能的高低主要由( )芯...
基础
各位兄弟,在SDK编程中如果实现窗口分割呢?请问怎么得到一个函数的执行时间,单位毫秒!如何调试asp组件呀。用vc++调试编制的组件怎样画一个箭头?
高分
请教如何限制程序运行的方法?
求助
:通过编程DirectX抓屏------>masterz:再麻烦你一下,谢谢熟悉RichEdit的朋友过来看一下,RichEdit的几个问题.如何对 I/O 端口进行操作?有了该问题就有了思考(100分 献礼!)如何
送你一个目录,一站式学习生信!众多干货,有趣有料!
生信的作用越来越大,想学的人越来越多,不管是为了以后发展,还是为了解决眼下的问题。但生信学习不是一朝一夕就可以完成的事情,也许你可以很短时间学会一个交互式软件的操作,却不能看完程序教学视频...
数据库帖子收集
这样的数据列表在存储过程中应该怎么样选择得到? 请问造成SQL2000服务不能启动的原因有哪些? sql server中有無類似于if 的函數,即像這樣select if(cancel=1,'cancel','') from sales 这样怎么返回呀!!!!记录集的返回。。 谁能跟我说说期初库存怎么样的一个业务逻辑!都要处理哪些内容!需要每月进...
Web 开发
81,122
社区成员
341,744
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章