我的jsp页面的代码如下,可是运行后只显示了顶部的内容,有java代码的部分却没显示 并且后台显示如题的错误
<body>
<%
String user=(String)session.getAttribute("user");
%>
<center>
<table width="1043" border="0">
<tr>
<td width="60"><div id="my" align="center"><a href="#">技术论坛首页</a></div></td>
<td width="50"><div align="center"><a href="#">资讯</a></div></td>
<td width="50"><div align="center"><a href="#">论坛</a></div></td>
<td width="50"><div align="center"><a href="#">博客</a></div></td>
<td width="50"><div align="center"><a href="#">下载</a></div></td>
<td width="50"><div align="center"><a href="#">搜索</a></div></td>
<td width="50"><div align="center"><a href="#">更多</a></div></td>
<td width="50"><div align="center">欢迎</div></td>
<td width="50"><div align="center"><%=user %></div></td>
<td width="50"><div align="center"><a href="loginout.jsp">退出</a></div></td>
</tr>
<%
Boardinfo bi=new Boardinfo();
ArrayList al=bi.getBoard();
for(int i=0;i<al.size();i++) {
BoardBean bb=(BoardBean)al.get(i);
%>
<tr>
<td><%=bb.getBoardname() %></td><td><%=bb.getBoardid() %></td>
</tr>
<% }%>
</table>
</center>
</body>
其他相关代码为
public ArrayList getBoard(){
ArrayList al=new ArrayList();
try{
Class.forName("com.mysql.jdbc.Driver");
ct=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/user","root","523325");
st=ct.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs=st.executeQuery("select BoardName from board");
while(rs.next()){
BoardBean bb=new BoardBean();
bb.setBoardid(rs.getInt("BoardId"));
bb.setBoardname(rs.getString("BoardName"));
al.add(bb);
}
还有以下的相关代码public class BoardBean {
private int boardid;
private String boardname;
public int getBoardid() {
return boardid;
}
public void setBoardid(int boardid) {
this.boardid = boardid;
}
public String getBoardname() {
return boardname;
}
public void setBoardname(String boardname) {
this.boardname = boardname;
}
}我不知道错在哪 请高手指点哈谢谢
------解决方案--------------------
你查询的具体代码是 rs=st.executeQuery("select BoardName from board");
也就是你只查询了一列boardname存储到rs里面,而后面你又 调用rs.getInt("BoardId")试图从rs读取boardid这个字段,而rs里面没有,所以出错
首先确保board这个表里面有 boardname和boardid这两个字段
第二,修改rs=st.executeQuery("select BoardName from board");
为rs=st.executeQuery("select boardid,boardName from board");