<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@page import =java.util.* %>
<%
application.setAttribute("ip",request.getRemoteAddr());
List<String> list =new ArrayList<String>();
list.add( application.getAttribute("ip"));
int number=0;
Iterator<String> it =list.iterator();
while(it.hasNext())
{
if (application.getAttribute("number")==null)
number=1;
else if(it.next()!=request.getRemoteAddr())
{
number=Integer.parseInt((String)application.getAttribute("number"));
number=number+1;
}
}
out.print("你是第"+number+"位访问者!");
application.setAttribute("number",String.valueOf(number));
%>
<!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>Insert title here</title>
</head>
<body>
</body>
</html>
9 个解决方案
#1
求助啊 求助啊
#2
悲剧。。。
<%@page import =java.util.* %>
变成
<%@page import="java.util.*"%>
<%@page import =java.util.* %>
变成
<%@page import="java.util.*"%>
#3
application这个是要大写的~
其他还有什么错误发上来看一下,代码应该没有什么大的问题~
不过针对这个题,这样的做法似乎不怎么好,难道一个IP地址的多次访问就是一个号吗?
其他还有什么错误发上来看一下,代码应该没有什么大的问题~
不过针对这个题,这样的做法似乎不怎么好,难道一个IP地址的多次访问就是一个号吗?
#4
试一下这个看行不?
Count.java
package mypack;
public class Counter
{
long count=0;
public long getCount()
{
return count;
}
public synchronized void setCount()
{
count++;
}
}
count.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<jsp:useBean id="counter" class="mypack.Counter" scope="application">
</jsp:useBean>
<html>
<head>
<title>
用javabean作计数器
</title>
</head>
<body>
<% if(application.isNew())
counter.setCount();
%>
<p><p>欢迎你来你是第
<%=counter.getCount() %>
个用户
</body>
</html>
#5
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the jsp file: /s.jsp
The method add(String) in the type List<String> is not applicable for the arguments (Object)
5:
6: application.setAttribute("ip",request.getRemoteAddr());
7: List<String> list =new ArrayList<String>();
8: list.add( application.getAttribute("ip"));
9: int number=0;
10: Iterator<String> it =list.iterator();
11: while(it.hasNext())
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
这个是异常
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the jsp file: /s.jsp
The method add(String) in the type List<String> is not applicable for the arguments (Object)
5:
6: application.setAttribute("ip",request.getRemoteAddr());
7: List<String> list =new ArrayList<String>();
8: list.add( application.getAttribute("ip"));
9: int number=0;
10: Iterator<String> it =list.iterator();
11: while(it.hasNext())
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
这个是异常
#6
application.getAttribute("ip") 返回的是Object,你定义的String。当然报了The method add(String) in the type List<String> is not applicable for the arguments (Object)
#7
怎么改啊 还有一个问题就是 我这样LIST不是APPLICATION里面的 就算把IP存入LIST 也不能全局保存 怎么在APPLICATION中建立LIST啊
#8
来人啊 啊啊啊啊 啊
#9
1,session.isNew()可以判断是否是新的用户,避免重复
2,request.getSession(false)这样获取旧的session,判断是否为null
3,application这个是基础问题.不解了
#1
求助啊 求助啊
#2
悲剧。。。
<%@page import =java.util.* %>
变成
<%@page import="java.util.*"%>
<%@page import =java.util.* %>
变成
<%@page import="java.util.*"%>
#3
application这个是要大写的~
其他还有什么错误发上来看一下,代码应该没有什么大的问题~
不过针对这个题,这样的做法似乎不怎么好,难道一个IP地址的多次访问就是一个号吗?
其他还有什么错误发上来看一下,代码应该没有什么大的问题~
不过针对这个题,这样的做法似乎不怎么好,难道一个IP地址的多次访问就是一个号吗?
#4
试一下这个看行不?
Count.java
package mypack;
public class Counter
{
long count=0;
public long getCount()
{
return count;
}
public synchronized void setCount()
{
count++;
}
}
count.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<jsp:useBean id="counter" class="mypack.Counter" scope="application">
</jsp:useBean>
<html>
<head>
<title>
用javabean作计数器
</title>
</head>
<body>
<% if(application.isNew())
counter.setCount();
%>
<p><p>欢迎你来你是第
<%=counter.getCount() %>
个用户
</body>
</html>
#5
exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the jsp file: /s.jsp
The method add(String) in the type List<String> is not applicable for the arguments (Object)
5:
6: application.setAttribute("ip",request.getRemoteAddr());
7: List<String> list =new ArrayList<String>();
8: list.add( application.getAttribute("ip"));
9: int number=0;
10: Iterator<String> it =list.iterator();
11: while(it.hasNext())
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
这个是异常
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the jsp file: /s.jsp
The method add(String) in the type List<String> is not applicable for the arguments (Object)
5:
6: application.setAttribute("ip",request.getRemoteAddr());
7: List<String> list =new ArrayList<String>();
8: list.add( application.getAttribute("ip"));
9: int number=0;
10: Iterator<String> it =list.iterator();
11: while(it.hasNext())
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
这个是异常
#6
application.getAttribute("ip") 返回的是Object,你定义的String。当然报了The method add(String) in the type List<String> is not applicable for the arguments (Object)
#7
怎么改啊 还有一个问题就是 我这样LIST不是APPLICATION里面的 就算把IP存入LIST 也不能全局保存 怎么在APPLICATION中建立LIST啊
#8
来人啊 啊啊啊啊 啊
#9
1,session.isNew()可以判断是否是新的用户,避免重复
2,request.getSession(false)这样获取旧的session,判断是否为null
3,application这个是基础问题.不解了