---------------------
jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="confirm" scope="request" class="firm.confirm"/>
<%
String sql;
ResultSet r=null;
int num[]=new int[4];
for(int j=1;j<=4;j++)
{
sql="select * from TVote where id='"+j+"'";
out.println(sql);
List list=confirm.executeQuery(sql);
Map map = (Map)list.get(0);
//num[j-1]=Integer.parseInt(r.getString("num"));
num[j-1]=Integer.parseInt((String)map.get("num"));
}
int total=0;
float voteFlo[]=new float[5];
for(int i=0;i<4;i++) total+=num[i];
for(int i=0;i<4;i++) voteFlo[i]=150*((float)num[i]/(float)total);
%>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查看调查</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body><table width="80%" border="0" class="t1" align="center">
<tr>
<td colspan="2"><div align="center">调查结果</div></td>
</tr>
<tr>
<td width="18%">JSP</td>
<td width="82%"><img src="red.jpg" width="<%=voteFlo[0]%>" height=8> <%=num[0]%></td>
</tr>
<tr>
<td>ASP</td>
<td><img src="red.jpg" width="<%=voteFlo[1]%>" height=8> <%=num[1]%></td>
</tr>
<tr>
<td>PHP</td>
<td><img src="red.jpg" width="<%=voteFlo[2]%>" height=8> <%=num[2]%></td>
</tr>
<tr>
<td>其他</td>
<td><img src="red.jpg" width="<%=voteFlo[3]%>" height=8> <%=num[3]%></td>
</tr>
<tr>
<td colspan="2"><div align="center"><a href="javascript:window.close();">关闭窗口</a></div></td>
</tr></table></body></html>
--------------------------------
bean中的executeQuery(sql)为:
public List executeQuery(String sql)
{
List list = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
System.out.println("YYYYY");
Class.forName(sDBDriver);
System.out.println("XXXXX");
conn = DriverManager.getConnection(sConnStr);
System.out.println("ZZZZZ");
stmt = conn.createStatement();
System.out.println("AAAAA");
rs = stmt.executeQuery(sql);
System.out.println("BBBBB");
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("CCCCC");
while ( rs.next() )
{
System.out.println("DDDDD");
Map map = new HashMap();
for ( int i = 1; i <= rsmd.getColumnCount(); i++ )
{
//System.out.println("map.put("+rsmd.getColumnName(i)+","+rs.getString(i)+")");
//System.out.println("KKKKK");
//String aaa=rs.getString(i);
//System.out.println("KKKKK");
//if(aaa==null)
// {aaa="UUU";
//System.out.println(aaa);}
// else
//System.out.println(aaa);
//map.put(rsmd.getColumnName(i), rs.getString(i));
map.put(rsmd.getColumnName(i),rs.getString(i));
System.out.println("SSSSS");
}
list.add(map);
}
}
catch ( Exception e )
{
e.printStackTrace();
}
finally
{
try
{
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
}catch (Exception e) {
e.printStackTrace();
}
}
return list;
}----------------------
现报错为:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Index: 0, Size: 0
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.RangeCheck(ArrayList.java:508)
java.util.ArrayList.get(ArrayList.java:320)
org.apache.jsp.chakan_jsp._jspService(chakan_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
实在想不出怎么错了,
各位看出来的冒个泡吧!
jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="confirm" scope="request" class="firm.confirm"/>
<%
String sql;
ResultSet r=null;
int num[]=new int[4];
for(int j=1;j<=4;j++)
{
sql="select * from TVote where id='"+j+"'";
out.println(sql);
List list=confirm.executeQuery(sql);
Map map = (Map)list.get(0);
//num[j-1]=Integer.parseInt(r.getString("num"));
num[j-1]=Integer.parseInt((String)map.get("num"));
}
int total=0;
float voteFlo[]=new float[5];
for(int i=0;i<4;i++) total+=num[i];
for(int i=0;i<4;i++) voteFlo[i]=150*((float)num[i]/(float)total);
%>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查看调查</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body><table width="80%" border="0" class="t1" align="center">
<tr>
<td colspan="2"><div align="center">调查结果</div></td>
</tr>
<tr>
<td width="18%">JSP</td>
<td width="82%"><img src="red.jpg" width="<%=voteFlo[0]%>" height=8> <%=num[0]%></td>
</tr>
<tr>
<td>ASP</td>
<td><img src="red.jpg" width="<%=voteFlo[1]%>" height=8> <%=num[1]%></td>
</tr>
<tr>
<td>PHP</td>
<td><img src="red.jpg" width="<%=voteFlo[2]%>" height=8> <%=num[2]%></td>
</tr>
<tr>
<td>其他</td>
<td><img src="red.jpg" width="<%=voteFlo[3]%>" height=8> <%=num[3]%></td>
</tr>
<tr>
<td colspan="2"><div align="center"><a href="javascript:window.close();">关闭窗口</a></div></td>
</tr></table></body></html>
--------------------------------
bean中的executeQuery(sql)为:
public List executeQuery(String sql)
{
List list = new ArrayList();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
System.out.println("YYYYY");
Class.forName(sDBDriver);
System.out.println("XXXXX");
conn = DriverManager.getConnection(sConnStr);
System.out.println("ZZZZZ");
stmt = conn.createStatement();
System.out.println("AAAAA");
rs = stmt.executeQuery(sql);
System.out.println("BBBBB");
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("CCCCC");
while ( rs.next() )
{
System.out.println("DDDDD");
Map map = new HashMap();
for ( int i = 1; i <= rsmd.getColumnCount(); i++ )
{
//System.out.println("map.put("+rsmd.getColumnName(i)+","+rs.getString(i)+")");
//System.out.println("KKKKK");
//String aaa=rs.getString(i);
//System.out.println("KKKKK");
//if(aaa==null)
// {aaa="UUU";
//System.out.println(aaa);}
// else
//System.out.println(aaa);
//map.put(rsmd.getColumnName(i), rs.getString(i));
map.put(rsmd.getColumnName(i),rs.getString(i));
System.out.println("SSSSS");
}
list.add(map);
}
}
catch ( Exception e )
{
e.printStackTrace();
}
finally
{
try
{
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
}catch (Exception e) {
e.printStackTrace();
}
}
return list;
}----------------------
现报错为:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Index: 0, Size: 0
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.util.ArrayList.RangeCheck(ArrayList.java:508)
java.util.ArrayList.get(ArrayList.java:320)
org.apache.jsp.chakan_jsp._jspService(chakan_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
实在想不出怎么错了,
各位看出来的冒个泡吧!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货