<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>对于对象application的应用:计数器</title>
</head>
<%@ page import="java.lang.*" %>
<body>
<%
int i;
%>
<%
application.setAttribute("counter",String.valueOf(i++));
%>
<%=i%>
</body>
</html>
错在哪里?????
------解决方案--------------------
<%@ page import="java.lang.*" %> 没得必要用,因为JSP已经缺省把那个java.lang.* 包里的东西都包含进去了!
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" >
<head >
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" / >
<title >对于对象application的应用:计数器 </title >
</head >
<body >
<%
int i=0;
%>
<%
application.setAttribute("counter",String.valueOf(i++));
%>
<%=i%>
</body >
</html >
------解决方案--------------------
这个页面有两个错误,变量i没有初始化,应该赋值为0,ls所说的<%@ page import="java.lang.*" % > 没得必要用,因为JSP已经缺省把那个java.lang.* 包里的东西都包含进去了!是正确的,错误2在于“% >”的前面都有一个空格,去掉该改成“%>”就OK了,ls的也没注意到这点啊,正确的代码如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>对于对象application的应用:计数器 </title>
</head>
<%@ page import="java.lang.*" %>
<body>
<%
int i = 0;
%>
<%
application.setAttribute("counter",String.valueOf(i++));
%>
<%=i%>
</body>
</html>