照着书上敲的,总是错。程序的目的是创建一个名为Count的JavaBeans组件,用它来统计访问JSP网页的次数。
代码如下:
<!-- TestBeanScope.jsp -->
<%@ page import = "chapter35.Count" %>
<jsp:useBean id = "count" scope = "application" class = "chapter35.Count" />
</jsp:useBean>
<html>
<head>
<title>TestBeanScope</title>
<head>
<body>
<h3>Testing Bean Scope in JSP (Application)</h3>
<% count.increaseCount(); %>
You are visitor number <%= count.getCount() %><br />
From host: <%= request.getRemoteHost() %>
and session: <%= sessiongetId() %>
</body>
</html>
package chapter35;
public class Count
{
private int count = 0;
/** Return count property */
public int getCount()
{
return count;
}
/** Increase count */
public void increaseCount()
{
count++;
}
}
编译好的class文件放在WEB-INF/classes/chapter35下,为什么运行后总是显示成下面这样啊
代码错了。。。在第一行添加<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>这个看下。然后修改session获取ID那里.