jsp 小问题 只有我不会 高分相送

nuboy 2004-10-31 07:01:27
这是一个考试系统的JSP页面
从其他页面传来了答案
想把他们存成数组
paramValues[]
从数据库中取出正确答案
也存成数组
daan[]
运行事报错
源码是
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<title>dafen.jsp</title>
</head>
<body bgcolor="eeffee">
<%!
String[] paramValues;//考生答案
String[] daan;//正确答案
%>
<%
int i=0;int j=0;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:kaoshi");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery("SELECT * FROM shiti");

while(rs.next())
{
daan[j]= rs.getString("daan");
j++;
}
rs.close();
stmt.close();
con.close();//取得正确答案


Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
paramValues[i] = request.getParameterValues(paramName);
i++;
}//取得考生答案
%>
</body>
</html>

错误是
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 13 in the jsp file: /dafen.jsp

Generated servlet error:
[javac] Compiling 1 source file

E:\张子平\xml\Tomcat 4.1\work\Standalone\localhost\_\dafen_jsp.java:79: incompatible types
found : java.lang.String[]
required: java.lang.String
paramValues[i] = request.getParameterValues(paramName);
^
...全文
104 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
JIEK_ONE 2004-10-31
  • 打赏
  • 举报
回复
java.lang.NullPointerException
at org.apache.jsp.dafen_jsp._jspService(dafen_jsp.java:68)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204

以前我也发生过这样的问题,后面发现是我的程序没有连上数据库,你看看是不是这个原因。
neujyj 2004-10-31
  • 打赏
  • 举报
回复
paramValues[i] = request.getParameterValues(paramName);
paramValues[i]为String对象
request.getParameterValues(paramName); 返回数组的引用
两者不一致

dropship 2004-10-31
  • 打赏
  • 举报
回复
String paramName = (String)paramNames.nextElement();
这句出错。
你看下生成的java文件,应该能够看到
我猜原因是没有参数传递过来,所以要么是
转型为string出错,要么是
下一句,getparameter(null)//因为paramName为null
nuboy 2004-10-31
  • 打赏
  • 举报
回复
该了之后'又报错
java.lang.NullPointerException
at org.apache.jsp.dafen_jsp._jspService(dafen_jsp.java:68)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204
myxd 2004-10-31
  • 打赏
  • 举报
回复
request.getParameterValues(paramName);

该为
request.getParameter(paramName);

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧