<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>session示例</title>
</head>
<body>
<center>
<%
Integer counter = (Integer)session.getAttibute("accessCount");
if(counter==null){
out.println("你是首次来访<br>");
counter = new Integer(0);
}
else{
out.println("欢迎回访<br>");
counter = new Integer(counter.intValue()+1);
}
session.setAttribute("accessCount",counter);
%>
<hr>
<%=counter %>
</center>
</body>
</html>这是jsp的代码
在eclipse中运行报错:
An error occurred at line: 12 in the jsp file: /sessionCounter.jsp
The method getAttibute(String) is undefined for the type HttpSession
网上找了半天都没有回答,帮忙解决下
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>session示例</title>
</head>
<body>
<center>
<%
Integer counter = (Integer)session.getAttibute("accessCount");
if(counter==null){
out.println("你是首次来访<br>");
counter = new Integer(0);
}
else{
out.println("欢迎回访<br>");
counter = new Integer(counter.intValue()+1);
}
session.setAttribute("accessCount",counter);
%>
<hr>
<%=counter %>
</center>
</body>
</html>这是jsp的代码
在eclipse中运行报错:
An error occurred at line: 12 in the jsp file: /sessionCounter.jsp
The method getAttibute(String) is undefined for the type HttpSession
网上找了半天都没有回答,帮忙解决下
难道你没有使用myeclipse,不然会提示错误的。
应该是getAttribute("accessCount")少了个i
我运行了下你的可以
应该是这句
Integer counter = (Integer) session.getAttribute("accessCount");
if (counter == null) {
out.println("你是首次来访 <br>");
counter = new Integer(0);
} else {
out.println("欢迎回访 <br>");
counter = new Integer(counter.intValue() + 1);
}
session.setAttribute("accessCount", counter);
%>
<hr>
<%=counter%>这段代码我试了
没问题
getAttibute()方法写错了 getAttribute(); 应该是