testjsp.jsp必须放在myapps根目录下
testbean.class放到classes目录下的test目录中

解决方案 »

  1.   

    我的testjsp.jsp的代码如下:
    <%@ page import="testbean" %> 
    改成:
    我的testjsp.jsp的代码如下:
    <%@ page import="test.testbean" %>test.TestBean这个类有吗? 
      

  2.   

    我的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;

    }
      

  3.   

    --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;

    }
      

  4.   

    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有办法帮我解决吗?谢谢!
      

  5.   

    default package不需要import的吧
      

  6.   

    你的testbean.class文件怎么这么奇怪呀