jsp+javabeans的显示小问题
input.jsp
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body>
<table width= "560 " border= "0 " cellpadding= "0 " cellspacing= "0 ">
<!--DWLayoutTable-->
<form name= "form1 " method= "post " action= "input2.jsp ">
<tr>
<td height= "42 " colspan= "2 " valign= "top "> 测试: </td>
</tr>
<tr>
<td width= "121 " height= "26 " align= "right " valign= "top "> 性别: </td>
<td width= "439 " valign= "top ">
<input type= "radio " name= "gender " value= "male ">
男
<input type= "radio " name= "gender " value= "female ">
女
</td>
</tr>
<tr>
<td height= "24 " align= "right " valign= "top "> 年龄: </td>
<td valign= "top "> <input type= "text " name= "age "> </td>
</tr>
<tr>
<td height= "24 " align= "right " valign= "top "> 体重: </td>
<td valign= "top "> <input type= "text " name= "weight "> </td>
</tr>
<tr>
<td height= "27 " valign= "top "> <input type= "submit " name= "Submit " value= "提交 "> </td>
<td valign= "top "> <!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height= "158 "> </td>
<td> </td>
</tr> </form>
</table>
</body>
</html>
input2.jsp
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<jsp:useBean id = "Calculator " class = "CalMeasure " scope= "session " />
<jsp:setProperty name = "Calculator " property= "* " />
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 无标题文档 </title>
</head>
<body>
你的结果: <jsp:getProperty name= "Calculator " property= "result " />
</body>
</html>
CalMeasure.class
import java.io.*;
public class CalMeasure {
int weight;
int age;
int result =0;//1
String gender;
public CalMeasure(){
}
public int getWeight(){
return this.weight;
}
public int getAge(){
return this.age;
}
public String getGender(){
return this.gender;
}
public int getResult(){
return calculate();//
}
public void setWeight(int weight_){
this.weight = weight_;
}
public void setAge(int age_){
this.age = age_;
}
public void setGender(String gender_){
this.gender = gender_;
}
private int calculate(){
if(this.result!=0){
return this.result;
}else{
float fltTEN = (float)(weight * 2); //2
this.result = (int)fltTEN;//2;
return this.result;//////////////
}//else
}
public static void main(String[] args) {
CalMeasure p=new CalMeasure();
System.out.println(p.calculate());
}
}//class
出现错误:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /input2.jsp(3,0) The value for the useBean class attribute CalMeasure is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
请问是怎么回事啊?????????
------解决方案--------------------
<jsp:useBean id = "Calculator " class = "CalMeasure " scope= "session " />
记得要带上包名的吧
错误提示的是CalMeasure这个东西不存在似的
[解决办法]
你的javaBean里还有这个: public static void main(String[] args) {
CalMeasure p=new CalMeasure();
System.out.println(p.calculate());
}
呵呵..只有方法.
[解决办法]
我的也有类似问题,麻烦顺便看一下我这是什么问题
<jsp:useBean id= "dbConn " class= "org.apache.jsp.ereport " scope= "page "/>
<jsp:useBean id= "file " class= "org.apache.jsp.FileUpload " scope= "page "/>
exception
javax.servlet.ServletException: org/apache/jsp/ereport
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.NoClassDefFoundError: org/apache/jsp/ereport
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:137)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:307)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html