问题:建一个监听类来实现一个访问次数在myeclipse里建一个WebTest We工程
建好了.建一个类名叫Count.java
Count内容是public class Count {  public Count(){}
 
 public static int count=0;
 public static void up(){
   count++;
 }
 public static void down(){
  count--;
 }
 public static int resultSet(){
 return count;
 }
}在建一个Servlet类继承自HttpSessionLister内容是:import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class CountServlet extends HttpServlet implements HttpSessionListener { public void sessionCreated(HttpSessionEvent arg0) {

Count.up();
// TODO Auto-generated method stub } public void sessionDestroyed(HttpSessionEvent arg0) {

Count.down();
// TODO Auto-generated method stub } /**
 * Constructor of the object.
 */
public CountServlet() {
super();
} /**
 * Destruction of the servlet. <br>
 */
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
 * Initialization of the servlet. <br>
 *
 * @throws ServletException if an error occure
 */
public void init() throws ServletException {
// Put your code here
}}在建一个显示的JSP名叫show.jsp内容是:
<%@ page language="java" import="java.util.*" 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>My JSP 'show.jsp' starting page</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>
   访问次数是<%=Count.resultSet() %>
  </body>
</html>
在http://127.0.0.1:8080/WebTest/show.jsp在运行时。出现500大字。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: 26 in the jsp file: /show.jsp
Generated servlet error:
Count cannot be resolved
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 26 in the jsp file: /show.jsp
Generated servlet error:
Count cannot be resolved
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
弄不清楚 吖。。求救

解决方案 »

  1.   

    访问次数是 <%=Count.resultSet()   %>
    这里的Count哪里来的?如果是你自己写的java class的话,要先引入到JSP来才行.
      

  2.   

    我可以点出来吖。。不用导吖???开发JSP.什么时候要配WEB.XML??这个用上工具不是很知道。初学者。在线等我在WEB。XML没有配置。能出来吗??
      

  3.   

    将Count 与CountServlet 放在一个包下面,在jsp中写<%=包名.Count.resultSet()   %>就行了
      

  4.   

    不用配web.xml吗??
    我在JB里也是这样做的。??没有错吖。来到MYECLIPSE出大500吖???
      

  5.   

    xml 中写的东西为:
    <servlet>
        <description>This is the description of my J2EE component</description>
        <display-name>This is the display name of my J2EE component</display-name>
        <servlet-name>CountServlet</servlet-name>
        <servlet-class>包名.CountServlet</servlet-class>
      </servlet>  <servlet-mapping>
        <servlet-name>CountServlet</servlet-name>
        <url-pattern>/servlet/CountServlet</url-pattern>
      </servlet-mapping>
    但用MYECLIPSE,此web.xml制动生成