日期:2014-05-18  浏览次数:20914 次

编译时出现org.apache.jasper.JasperException: Exception in JSP: /index.jsp:11
源代码如下:  
GetUserInfo.java代码:  
package   testbeans;  
import   java.sql.*;  
import   java.util.*;  
public   class   GetUserInfo   {  
public   Connection   con;  
public   GetUserInfo(){  
try{  
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");  
String   ulr= "jdbc:odbc:forum ";  
String   user= " ";  
String   pwd= " ";  
con=DriverManager.getConnection(ulr,user,pwd);  

}   catch(Exception   e)  
{e.printStackTrace();  
}  
}  
public   Vector   getInfo()  
{   Vector   result=new   Vector();  
String   sql= "select   *   from   topic ";  
try{  
Statement   stmt=con.createStatement();  
ResultSet   rs=stmt.executeQuery(sql);  
while(rs.next()){  
String   author=rs.getString( "author ");  
result.addElement(author);  
String   subject=rs.getString( "subject ");  
result.addElement(subject);  
String   email=rs.getString( "email ");  
result.addElement(email);  
String   content=rs.getString( "content ");  
result.addElement(content);  
}  
rs.close();  
stmt.close();  
con.close();  
}catch(Exception   e){}  
return   result;  
}  
}  

index.jsp代码:  
<%@page   contentType= "text/html;charset=gb2312 "import= "java.util.* "   %>  
<jsp:useBean   id= "info "   scope= "page "   class= "testbeans.GetUserInfo ">  
</jsp:useBean>  
<%  
Vector   vec=info.getInfo();  
int   count=vec.size();  
out.print(count);  
String   str=new   String( " ");  
for(int   i=0;i <count;i++)  
{  
str+=vec.elementAt(i).toString();  
}  
if(count!=0)  
{out.print(str);}  
%>  
编译时报错:  
org.apache.jasper.JasperException:   Exception   in   JSP:   /index.jsp:11  

8:   String   str=new   String( " ");  
9:   for(int   i=0;i <count;i++)  
10:   {  
11:   str+=vec.elementAt(i).toString();  
12:   }  
13:   if(count!=0)  
14:   {out.print(str);}  

如果不用循环,只写str=vec.elementAt(1).toString()可以得出正确结束,但是用循环却不行,请高手帮我纠正一下,谢谢了!

------解决方案--------------------
试试这样:
8: String str= " ";
9: for(int i=0;i <count;i++)
10: {
11: str+=(String)vec.get(i);
12: }
13: if(count!=0)
14: {out.print(str);}