急!求助,javaBean的问题
我的Java报错:
org.apache.jasper.JasperException: /test.jsp(32,2) GetProperty: Mandatory attribute property missing
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:198)
org.apache.jasper.compiler.JspUtil.checkAttributes(JspUtil.java:284)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:470)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1063)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2164)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2214)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2220)
org.apache.jasper.compiler.Node$Root.accept(Node.java:457)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2164)
org.apache.jasper.compiler.Validator.validate(Validator.java:1484)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:296)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
全部代码如下:
<Test.java>
package tom.jiafei;
import java.io.*;
public class Test
{
String fileName= " ",//存放考题文件名字的字符串
correctAnswer= " ", //存放正确答案的字符串
testContent= " ", //存放试题的字符串
selection= " "; //客户提交的答案的字符串
int score=0;
public void setFileName(String name){
fileName=name;
selection= " ";
score=0;
}
public String getFileName(){
return fileName;
}
public String getCorrectAnswer(){//读取试题文件的第一行:标准答案
try{
File f=new File( "D:/2000 ",fileName);
FileReader in=new FileReader(f);
BufferedReader buffer=new BufferedReader(in);
correctAnswer=(buffer.readLine()).trim();//读取第一行去掉前后空格
buffer.close();
in.close();
}
catch(Exception e){}
if(selection.length()> 0)
return correctAnswer;
else
return "提交答案后,可以看到正确答案 ";
}
public String getTestContent(){
StringBuffer temp=new StringBuffer();
try{
if(fileName.length()> 0){
File f=new File( "D:/2000 ",fileName);
FileReader in=new FileReader(f);
BufferedReader buffer=new BufferedReader(in);
String str=buffer.readLine();//该行不显示给用户
while ((str=buffer.readLine())!=null){//读出全部题目
temp.append( "\n "+str);
}
buffer.close();
in.close();
}
}
catch(Exception e){}
return " <TextArea rows=15 cols=80> "+new String(temp)+ " </TextArea> ";
}
public void setSelection(String s){
selection=s.trim();
}
public String getSelection(){
return selection;
}
public int getScore(){
score=0;
int length1=selection.length();
int length2=correctAnswer.length();
int min=(int)(Math.min(length1,length2));
int i=0;
while(i <min){
if(selection.charAt(i)==correctAnswer.charAt(i))
score++;
i++;
}
return score;
}
}
test.jsp
<%@ page contentType= "text/html;charset=GB2312 "%>
<%@ page import= "tom.jiafei.Test "%>
<html>
<body>
<font size=2>
<jsp:useBean id= "test "class= "tom.jiafei.Test "scope= "session ">
<br> 请选择试题:
<form action= " "method= "post "name=form1>
<Select name= "fileName "value= "A.txt ">
<Option value= "A.txt "> A.txt
<Option value= "B.txt "> B.txt
<Option value= "C.txt "> C.txt
</Select>
<input type=submit value= "确定 "name= "sub ">
</form>
<jsp:setProperty name= "test " property= "fileName "param= "fileName "/>
<br> 试题内容如下:
<br> <jsp:getProperty name= "test " property= "testContent "/> <br>
<form action= " "method= "post " name=form2>
在文本框中输入全部问题的答案,答案之间不允许有空格:
<br> <input type=text name= "selection "size=80>
<input type= "submit " value= "提交 ">
</form>
<jsp:setProperty name= "test "property= "selection "param= "selection "/>
<br> 试题的正确答案:
<jsp:getProperty name= "test "property= "correctAnswer "/>
<br> 您提交的答案:
<jsp:getProperty name= "test "Property= "selection "/>
<br> 您的分数:
<jsp:getProperty name= "test "Property= "score "/>
</jsp:useBean>
</font>
</body>
</html>
[解决办法]
<br/> 试题的正确答案:
<jsp:getProperty name= "test "property= "correctAnswer "/>
<br/> 您提交的答案:
<jsp:getProperty name= "test "Property= "selection "/>
<br/> 您的分数:
<jsp:getProperty name= "test "Property= "score "/>
property 前加空格试试 property 首字母改小写试试