我的testbean.class写错了,应该是 public class testbean{ private String name = null; public testbean(String strName_p){ this.name=strName_p; } public void setName(String strName_p){ this.name=strName_p; } public String getName(){ return this.name; } }
--tomcat4.1 -- webapps ---myapps --testjsp.jsp --WEB-INF -----classes ------test --------testbean.class 先统一大小写,然后:jsp页面中:<%@ page import="test.testbean" %>bean里: testbean.class加package: package test; public class testbean{ private String name = null; public testbean(String strName_p){ this.name=strName_p; } public void setName(String strName_p){ this.name=strName_p; } public String getName(){ return this.name; } }
fft123,我按照你的做了,运行成功了!不过我还想问一个问题: 我的testjsp.jsp的代码如下: <%@ page import="testbean" %> //***不是import="test.testbean" <html> <body> <center> <% testbean testBean=new testbean("This is a test java bean."); %> Java bean name is: <%=testBean.getName()%> </center> </body> </html> 而 public class testbean{ //***不加上package test;这一句private String name = null; public testbean(String strName_p){ this.name=strName_p; } public void setName(String strName_p){ this.name=strName_p; } public String getName(){ return this.name; } }两个文件放的位置为: --tomcat4.1 -- webapps ---myapps --testjsp.jsp --WEB-INF -----classes ------testbean.class 为什么没法运行,其错误提示为: type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: -1 in the jsp file: nullGenerated servlet error: [javac] Compiling 1 source fileC:\Tomcat 4.1\work\Standalone\localhost\myapps\testjsp_jsp.java:7: '.' expected import testbean; ^ 1 error有办法帮我解决吗?谢谢!
<%@ page import="testbean" %>
改成:
我的testjsp.jsp的代码如下:
<%@ page import="test.testbean" %>test.TestBean这个类有吗?
public class testbean{
private String name = null;
public testbean(String strName_p){
this.name=strName_p;
}
public void setName(String strName_p){
this.name=strName_p;
}
public String getName(){
return this.name;
}
}
-- webapps
---myapps
--testjsp.jsp
--WEB-INF
-----classes
------test
--------testbean.class 先统一大小写,然后:jsp页面中:<%@ page import="test.testbean" %>bean里:
testbean.class加package:
package test;
public class testbean{
private String name = null;
public testbean(String strName_p){
this.name=strName_p;
}
public void setName(String strName_p){
this.name=strName_p;
}
public String getName(){
return this.name;
}
}
我的testjsp.jsp的代码如下:
<%@ page import="testbean" %> //***不是import="test.testbean"
<html>
<body>
<center>
<%
testbean testBean=new testbean("This is a test java bean.");
%>
Java bean name is: <%=testBean.getName()%>
</center>
</body>
</html> 而
public class testbean{ //***不加上package test;这一句private String name = null;
public testbean(String strName_p){
this.name=strName_p;
}
public void setName(String strName_p){
this.name=strName_p;
}
public String getName(){
return this.name;
}
}两个文件放的位置为:
--tomcat4.1
-- webapps
---myapps
--testjsp.jsp
--WEB-INF
-----classes
------testbean.class
为什么没法运行,其错误提示为:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: -1 in the jsp file: nullGenerated servlet error:
[javac] Compiling 1 source fileC:\Tomcat 4.1\work\Standalone\localhost\myapps\testjsp_jsp.java:7: '.' expected
import testbean;
^
1 error有办法帮我解决吗?谢谢!