辅仁阿胶怎么样:新学java的,在用tomcat的时候对javaBean的测试的时候出错了

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/06 02:36:32
我是新学java的,在用tomcat的时候根据书上所说完成了对.jsp文件的测试,但是在对javaBean的测试的时候出错了
源码如下,源码如下:
<%@ page contentType="text/html;charset=gb2312"
session="true" %>
<html>
<head>
<title>比较四种生命周期类型</title>
</head>
<body><div align="center">
<jsp:useBean id="compara" scope="page" class="c"/>
<hr>
<%=compara.getscopeType()%><br>
<%compara.setscopeType("request");%>
<hr>
</div></body>
</html>
出错为:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 7 in the jsp file: /s.jsp

Generated servlet error:
[javac] Compiling 1 source file

F:\apache-tomcat-4.1.32-LE-jdk14\work\Standalone\localhost\myJSP\s_jsp.java:42: cannot resolve symbol
symbol : class c
location: class org.apache.jsp.s_jsp
c compara = null;
^

An error occurred at line: 7 in the jsp file: /s.jsp

Generated servlet error:
F:\apache-tomcat-4.1.32-LE-jdk14\work\Standalone\localhost\myJSP\s_jsp.java:44: cannot resolve symbol
symbol : class c
location: class org.apache.jsp.s_jsp
compara = (c) pageContext.getAttribute("compara", PageContext.PAGE_SCOPE);
^

An error occurred at line: 7 in the jsp file: /s.jsp

Generated servlet error:
F:\apache-tomcat-4.1.32-LE-jdk14\work\Standalone\localhost\myJSP\s_jsp.java:47: cannot resolve symbol
symbol : class c
location: class org.apache.jsp.s_jsp
compara = (c) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "c");
^
3 errors
拜托各位帮忙!!

参考资料:http://www.djasp.net

cannot resolve symbol

这个异常是通常找不到该类所报的异常,你看看在useBean的class属性中类的包名和类名是否写错,或TOMCAT的部署是不是出错了,注意大小写

另外在第一行加上类的引用

<%@page import="包名和类名"%>

不然在(c)的强制转换中也会抛异常

你的类c都没有导入啊,肯定不能这样compara = (c) pageContext.getAttribute("compara", PageContext.PAGE_SCOPE); 用了。
加入<%page import="c" %>看看。