主题:JSP程序出现NullPointerException路过的请进来看看
lvjun106
[专家分:230] 发布于 2006-10-12 19:24:00
//文件1:LandingExamination.jsp
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*"%>
<% int i=1;
String str=null;
Integer number=new Integer(1);
Integer score=new Integer(0);
session.setAttribute("分数",score);
session.setAttribute("题号",number);
try{
File file=new File("C:/Program Files/Xinox Software/JCreatorV3/MyProjects/test/src","English.txt");
FileReader infile=new FileReader(file);
BufferedReader in=new BufferedReader(infile);
while((str=in.readLine())!=null){
session.setAttribute(""+i,str);
i++;
}
}catch(IOException e){
out.print("无法读取文件");
}
%>
<html>
<body bgcolor="pink">
<font size="7">
<p>请点击进入考试系统</p>
<form action="ExaminationTest.jsp" method="post" name="form">
<INPUT type="submit" value="进入系统" name="submit">
</form>
</font>
</body>
</html>
回复列表 (共4个回复)
沙发
lvjun106 [专家分:230] 发布于 2006-10-12 19:26:00
//文件2:ExaminationTest.jsp
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*"%>
<% int i=1;
String str=null;
Integer number=new Integer(1);
Integer score=new Integer(0);
session.setAttribute("分数",score);
session.setAttribute("题号",number);
try{
File file=new File("C:/Program Files/Xinox Software/JCreatorV3/MyProjects/test/src","English.txt");
FileReader infile=new FileReader(file);
BufferedReader in=new BufferedReader(infile);
while((str=in.readLine())!=null){
session.setAttribute(""+i,str);
i++;
}
}catch(IOException e){
out.print("无法读取文件");
}
%>
<html>
<body bgcolor="pink">
<font size="7">
<p>请点击进入考试系统</p>
<form action="ExaminationTest.jsp" method="post" name="form">
<INPUT type="submit" value="进入系统" name="submit">
</form>
</font>
</body>
</html>
板凳
lvjun106 [专家分:230] 发布于 2006-10-12 19:27:00
//文件2:ExaminationTest.jsp
<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<html>
<body>
<%
int cur_number=1;
int cur_score=0;
String option[]=new String[7];
if(!session.isNew()){
if((session.getAttribute("题号"))!=null){
cur_number=((Integer)(session.getAttribute("题号"))).intValue();
}else{
session.setAttribute("题号",new Integer(cur_number));
}
cur_score=((Integer)(session.getAttribute("分数"))).intValue();
}
String str=(String)session.getAttribute(""+cur_number);
if(str==null){
str="ended";
}
StringTokenizer fenxi=new StringTokenizer(str,"#");
for(int i=0;fenxi.hasMoreTokens();i++){
option[i]=fenxi.nextToken();
}
session.setAttribute("题号",new Integer(cur_number+1));
session.setAttribute("答案"+cur_number,option[5]);
%>
<p>试题<%= cur_number %>:</p>
<BR>
<%= option[0] %>
<p>请选择你的答案:
<BR>
<BR>
<BR>
<form action="ExaminationTest.jsp" method="post" name="form">
<input type="radio" name="R" value="A">A. <%= option[1] %><BR>
<input type="radio" name="R" value="B">B. <%= option[2] %><BR>
<input type="radio" name="R" value="C">C. <%= option[3] %><BR>
<input type="radio" name="R" value="D">D. <%= option[4] %><BR>
<input type="submit" name="submit" value="提交答案">
</form>
<%
String cur_answer=request.getParameter("R");
String answer=(String)session.getAttribute("答案"+(cur_number-1));
if(cur_answer==null){
answer="您未做出选择";
}
if(cur_answer.equals(answer)){
session.setAttribute("分数",new Integer(cur_score+1));
}
out.print("<BR>"+"您上一题选的答案是:"+cur_answer);
out.print("<BR>"+"上一题正确的答案是:"+answer);
out.print("<BR>"+"您现在的得分是:"+session.getAttribute("分数"));
%>
</body>
</html>
3 楼
lvjun106 [专家分:230] 发布于 2006-10-12 19:28:00
为什么会出现NullPointerException????请高手指点!
4 楼
wolfofshaolin [专家分:330] 发布于 2006-10-22 19:45:00
错误信息全贴出来,不然怎么看
我来回复