刚开始学javabean...请教各位前辈我的程序哪里有问题....我把类文件放在默认包下没有建立新包...类文件Compare.java如下import java.util.Date;public class Compare{
//设置两个日期
private Date firstDate;
private Date secondDate;
/*判断*/
public String compare()
{
if(firstDate.before(secondDate))
return "第一个时间早";
else if(secondDate.before(firstDate))
return "第二个时间早";
else return "两个时间相同";
}
//取得第一个时间
public Date getFirstDate()
{
return firstDate;
}
//设置第一个时间
public void setFirstDate(Date firstDate)
{
this.firstDate=firstDate;
}
//取得第二个时间
public Date getSecondDate()
{
return secondDate;
}
//设置第二个时间
public void setSecondDate(Date secondDate)
{
this.secondDate=secondDate;
}
}
在newCompare.jsp文件如下<%@ page language="java" import="java.util.*" import="java.util.Date" pageEncoding="gb2312"%><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>JSP示例程序2</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
    <jsp:useBean id="date" class="Compare" scope="page"></jsp:useBean>
    <%
     date.setFirstDate(new Date());
     date.setSecondDate(new Date(107,6,23));
    
     %>
     <font size="4"><strong>本页面展示比较两个日期时间的前后:</strong><br>
     第一个时间:<jsp:getProperty property="firstDate" name="date"/><br>
     第二个时间:<jsp:getProperty property="secondDate" name="date"/><br>
     <%out.println(date.compare()); %>
    </font>
  </body>
</html>在myeclips中没有错误
在浏览器中报错:
org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 27 in the jsp file: /newCompare.jsp
Compare cannot be resolved to a typeAn error occurred at line: 34 in the jsp file: /newCompare.jsp
Compare cannot be resolved to a type我用的tomcat...
应该不是tomcat的问题,能运行其他jsp网页
应该是类文件的问题...如果要是路径有问题myeclipse应该报错,现在已经能通过,就不该是路径问题...
我的class文件在"myeclipse\工程名\WebRoot\WEB-INF\classes"中请各位前辈帮忙分析分析~~~~先谢过!

解决方案 »

  1.   

    现在能确定是<jsp:useBean id="date" class="Compare" scope="page"></jsp:useBean>这句出的问题...语法有错误是么?
      

  2.   

    我的class文件在"myeclipse\工程名\WebRoot\WEB-INF\classes"中有没有Compare类?
    建议在src下建个包把Compare放进去...
    >_<
      

  3.   

    我用的是eclipse,在项目上点击右键→New→Package,输入包名称就行了,其实就是将scr放入同一个文件夹,但是新建文件夹有可能在编译的时候会说找不到,建议还是用软件创建包。