出现大500啦。。求救

xszsai 2007-12-04 10:08:34
问题:建一个监听类来实现一个访问次数

在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 report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An 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 JSP

An 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.


弄不清楚 吖。。求救。。。
...全文
67 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangRen_java 2007-12-04
  • 打赏
  • 举报
回复
在jb中为什么好用, 我不知道
wangRen_java 2007-12-04
  • 打赏
  • 举报
回复
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制动生成
xszsai 2007-12-04
  • 打赏
  • 举报
回复
不用配web.xml吗??
我在JB里也是这样做的。??没有错吖。。。。来到MYECLIPSE出大500吖???
wangRen_java 2007-12-04
  • 打赏
  • 举报
回复
将Count 与CountServlet 放在一个包下面,在jsp中写<%=包名.Count.resultSet() %>就行了
xszsai 2007-12-04
  • 打赏
  • 举报
回复
我可以点出来吖。。不用导吖???

开发JSP.什么时候要配WEB.XML??这个用上工具不是很知道。初学者。

在线等。。。

我在WEB。XML没有配置。能出来吗??
loveyt 2007-12-04
  • 打赏
  • 举报
回复
访问次数是 <%=Count.resultSet() %>
这里的Count哪里来的?如果是你自己写的java class的话,要先引入到JSP来才行.

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧