问题描述
书上有一道题要求统计访问量而且还要求刷新不能增加访问量我是这样做的运行全是错不知道怎么做求助<%@pagelanguage="java"contentType="text/html;charset=GB18030"pageEncoding="GB18030"%><%@pageimport=java.util.*%><%application.setAttribute("ip",request.getRemoteAddr());List<String>list=newArrayList<String>();list.add(application.getAttribute("ip"));intnumber=0;Iterator<String>it=list.iterator();while(it.hasNext()){if(application.getAttribute("number")==null)number=1;elseif(it.next()!=request.getRemoteAddr()){number=Integer.parseInt((String)application.getAttribute("number"));number=number+1;}}out.print("你是第"+number+"位访问者!");application.setAttribute("number",String.valueOf(number));%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><metahttp-equiv="Content-Type"content="text/html;charset=GB18030"><title>Inserttitlehere</title></head><body></body></html>
解决方案
解决方案二:
求助啊求助啊
解决方案三:
悲剧。。。<%@pageimport=java.util.*%>变成<%@pageimport="java.util.*"%>
解决方案四:
application这个是要大写的~其他还有什么错误发上来看一下,代码应该没有什么大的问题~不过针对这个题,这样的做法似乎不怎么好,难道一个IP地址的多次访问就是一个号吗?
解决方案五:
试一下这个看行不?Count.javapackagemypack;publicclassCounter{longcount=0;publiclonggetCount(){returncount;}publicsynchronizedvoidsetCount(){count++;}}count.jsp<%@pagecontentType="text/html;charset=gb2312"%><jsp:useBeanid="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>
解决方案六:
exceptionorg.apache.jasper.JasperException:UnabletocompileclassforJSP:Anerroroccurredatline:8inthejspfile:/s.jspThemethodadd(String)inthetypeList<String>isnotapplicableforthearguments(Object)5:6:application.setAttribute("ip",request.getRemoteAddr());7:List<String>list=newArrayList<String>();8:list.add(application.getAttribute("ip"));9:intnumber=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)这个是异常
解决方案七:
application.getAttribute("ip")返回的是Object,你定义的String。当然报了Themethodadd(String)inthetypeList<String>isnotapplicableforthearguments(Object)
解决方案八:
怎么改啊还有一个问题就是我这样LIST不是APPLICATION里面的就算把IP存入LIST也不能全局保存怎么在APPLICATION中建立LIST啊
解决方案九:
来人啊啊啊啊啊啊
解决方案十:
引用6楼pxjianke的回复:
application.getAttribute("ip")返回的是Object,你定义的String。当然报了Themethodadd(String)inthetypeList<String>isnotapplicableforthearguments(Object)
1,session.isNew()可以判断是否是新的用户,避免重复2,request.getSession(false)这样获取旧的session,判断是否为null3,application这个是基础问题.不解了