黑
黑衣人
Unregistered / Unconfirmed
GUEST, unregistred user!
小弟使用Tomcat 4.1.24,编辑器用NotePad,写了个BEAN,编译好的类文件放在WEB-INF/classes目录下,bean内容如下:
//------------------bean-------------------//
public class FirstBean
{ private String UserName = "";
private String UserPwd = "";
public void FirstBean()
{}
public void setUserName(String name)
{ this.UserName = name;
}
public void setUserPwd(String pwd)
{ this.UserPwd = pwd;
}
public String getUserName()
{ return UserName;
}
public String getUserPwd()
{ return UserPwd;
}
}
//--------------bean----------------//
然后在Jsp文件中调用,JSP文件内容如下:
//--------------JSP----------------//
<%@ page language="java" %>
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<head><title>调用JAVABEAN</title>
</head>
<body>
<jsp:useBean id="fb" scope="session" class="FirstBean" />
<jsp:setProperty name="fb" property="userName" value="111" />
<jsp:setProperty name="fb" property="userPwd" value="111" />
<hr>
<jsp:getProperty name="fb" property="userName" />
<jsp:getProperty name="fb" property="userPwd" />
</body>
</html>
//--------------JSP----------------//
运行时报错,错误如下:
//--------------error---------------//
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:49: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] FirstBean fb = null;
[javac] ^
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:51: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] fb = (FirstBean) pageContext.getAttribute("fb", PageContext.SESSION_SCOPE);
[javac] ^
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:54: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] fb = (FirstBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "FirstBean");
[javac] ^
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:71: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] out.print(JspRuntimeLibrary.toString((((FirstBean)pageContext.findAttribute("fb")).getUserName())));
[javac] ^
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:73: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] out.print(JspRuntimeLibrary.toString((((FirstBean)pageContext.findAttribute("fb")).getUserPwd())));
[javac] ^
[javac] 5 errors
//--------------error---------------//
这是怎么回事?在bean中一顶要用package吗?
//------------------bean-------------------//
public class FirstBean
{ private String UserName = "";
private String UserPwd = "";
public void FirstBean()
{}
public void setUserName(String name)
{ this.UserName = name;
}
public void setUserPwd(String pwd)
{ this.UserPwd = pwd;
}
public String getUserName()
{ return UserName;
}
public String getUserPwd()
{ return UserPwd;
}
}
//--------------bean----------------//
然后在Jsp文件中调用,JSP文件内容如下:
//--------------JSP----------------//
<%@ page language="java" %>
<%@ page contentType="text/html;charset=gb2312" %>
<html>
<head><title>调用JAVABEAN</title>
</head>
<body>
<jsp:useBean id="fb" scope="session" class="FirstBean" />
<jsp:setProperty name="fb" property="userName" value="111" />
<jsp:setProperty name="fb" property="userPwd" value="111" />
<hr>
<jsp:getProperty name="fb" property="userName" />
<jsp:getProperty name="fb" property="userPwd" />
</body>
</html>
//--------------JSP----------------//
运行时报错,错误如下:
//--------------error---------------//
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:49: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] FirstBean fb = null;
[javac] ^
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:51: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] fb = (FirstBean) pageContext.getAttribute("fb", PageContext.SESSION_SCOPE);
[javac] ^
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:54: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] fb = (FirstBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "FirstBean");
[javac] ^
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:71: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] out.print(JspRuntimeLibrary.toString((((FirstBean)pageContext.findAttribute("fb")).getUserName())));
[javac] ^
[javac] C:/Program Files/Tomcat/work/Standalone/localhost/_/UseBean0_jsp.java:73: cannot resolve symbol
[javac] symbol : class FirstBean
[javac] location: class org.apache.jsp.UseBean0_jsp
[javac] out.print(JspRuntimeLibrary.toString((((FirstBean)pageContext.findAttribute("fb")).getUserPwd())));
[javac] ^
[javac] 5 errors
//--------------error---------------//
这是怎么回事?在bean中一顶要用package吗?