
用<c:forEach>就行啊 不知道你是取的几条数据,一般都是查询数据库结果是放一个集合里面,然后在页面上显示的话就像这样
<c:forEach items="${deptlist}" var="dept" varStatus="vs">
<tr>
<td class="liebiao-c"><input type="checkbox" name="checkbox" id="checkbox" value="${deptdeptid}"/></td>
<td class="liebiao-c">${vsindex+1}</td>
<td class="liebiao-c">${deptdeptname}</td>
<td class="liebiao-c">${deptdeptdesc}</td>
<td class="liebiao-c">
<a href="javascript:update('${deptdeptid}');" class="p_l_5">修改</a>
</td>
</tr>
</c:forEach>
>
这里用到了两个文件,一个jsp文件一个javabean文件,通过jsp中调用javabean可以轻松读取文本文件,注意请放置一个文本文件afiletxt到web根目录的test目录下,javabean文件编译后将class文件放到对应的class目录下(tomcat环境)。
Readjsp
$#@60;html$#@62;
$#@60;head$#@62;
$#@60;title$#@62;读取一个文件$#@60;/title$#@62;
$#@60;/head$#@62;
$#@60;body bgcolor="#000000"$#@62;
$#@60;%--调用javabean --%$#@62;
$#@60;jsp:useBean id="reader" class="DelimitedDataFile" scope="request"$#@62;
$#@60;jsp:setProperty name="reader" property="path" value="/test/afiletxt" /$#@62;
$#@60;/jsp:useBean$#@62;
$#@60;h3$#@62;文件内容:$#@60;/h3$#@62;
$#@60;p$#@62;
$#@60;% int count = 0; %$#@62;
$#@60;% while (readernextRecord() != -1) { %$#@62;
$#@60;% count++; %$#@62;
$#@60;b$#@62;第$#@60;% outprint(count); %$#@62;行:$#@60;/b$#@62;
$#@60;% outprint(readerreturnRecord()); %$#@62;$#@60;br$#@62;
$#@60;% } %$#@62;
$#@60;/p$#@62;
$#@60;/body$#@62;
$#@60;/html$#@62;
//DelimitedDataFilejava bean文件源代码
//导入java包
import javaio;
import javautilStringTokenizer;
public class DelimitedDataFile
{
private String currentRecord = null;
private BufferedReader file;
private String path;
private StringTokenizer token;
//创建文件对象
public DelimitedDataFile()
{
file = new BufferedReader(new InputStreamReader(Systemin),1);
}
public DelimitedDataFile(String filePath) throws FileNotFoundException
{
path = filePath;
file = new BufferedReader(new FileReader(path));
}
//设置文件路径
public void setPath(String filePath)
{
ath = filePath;
try {
file = new BufferedReader(new
FileReader(path));
} catch (FileNotFoundException e) {
Systemoutprintln("file not found");
}
}
//得到文件路径
public String getPath() {
return path;
}
//关闭文件
public void fileClose() throws IOException
{
fileclose();
}
//读取下一行记录,若没有则返回-1
public int nextRecord()
{
int returnInt = -1;
try
{
currentRecord = filereadLine();
}
catch (IOException e)
{
Systemoutprintln("readLine problem, terminating");
}
if (currentRecord == null)
returnInt = -1;
else
{
token = new StringTokenizer(currentRecord);
returnInt = tokencountTokens();
}
return returnInt;
}
//以字符串的形式返回整个记录
public String returnRecord()
{
return currentRecord;
}
}
Mathrandom()方法产生的是一个0-1之间的随机数,如果要变成整数就这样
getList((int)(Mathrandom()10));
你就不会想办法啊。循环n次,并且把每次生成的随机数记下(用来判断是否是相同的随机数,如果相同就继续循环),直到生成的随机数有4个并且都不相同
以上就是关于jsp页面从数据库里面取出数据,怎么让它2行3列的显示出来全部的内容,包括:jsp页面从数据库里面取出数据,怎么让它2行3列的显示出来、JSP如何从数据库中取出数据存到session中,本人新手,给个示例代码看看。、基于JSP的web题库系统中的随机抽取试题。数据库用的my sql。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)