我想把计数器的数字显示改成图形的,应该怎么改呢?
就是有1.jpg,2.jpg,3.jpg...对应数字1,2,3...怎么用在jsp页面里?
应该是怎样的语句?
还有,怎么在页面里显示客户机的IP呢?
<%@ page contentType="text/html;charset=GB2312" %> <%@ page import="java.io.*" %> <HTML> <BODY> <%! int number=0; synchronized void countPeople() { if(number==0) { try{File f=new File("D:/tomcat","countPeople.txt"); FileInputStream in=new FileInputStream(f); DataInputStream dataIn=new DataInputStream(in); number=dataIn.readInt(); number++; in.close();dataIn.close(); } catch(FileNotFoundException e) { number++; try {File f=new File("D:/tomcat","countPeople.txt"); FileOutputStream out=new FileOutputStream(f); DataOutputStream dataOut=new DataOutputStream(out); dataOut.writeInt(number); out.close();dataOut.close(); } catch(IOException ee){} } catch(IOException ee) { } } else {number++; try{File f=new File("D:/tomcat","countPeople.txt"); FileOutputStream out=new FileOutputStream(f); DataOutputStream dataOut=new DataOutputStream(out); dataOut.writeInt(number); out.close();dataOut.close(); } catch(FileNotFoundException e){} catch(IOException e){} } } %> <% if(session.isNew()) {countPeople(); String str=String.valueOf(number); session.setAttribute("count",str); } %> <P>您是第<%=(String)session.getAttribute("count")%>个访问本站的人。 <BODY> <HTML>
----------------解决方案--------------------------------------------------------
你的数字显示也是一个参数是吧?假设这个参数是n,为int型,在这个参数显示地方加上<img src="<%=n%>.jpg">就可以了
至于客户端得ip,可以用request.getRemoteAddr()获得,要显示的话让他输出就好了
----------------解决方案--------------------------------------------------------
能不能再说的清楚点,还是有点不明白哦
----------------解决方案--------------------------------------------------------
举个例子说:
如果你本来的程序是
<%
.......................
int n;
........
%>
...............
<%=n%>...................
这样显示的是数据1,2。。。。。。。。。。。
如果写成这样
<%
......................
int n;
....................
%>
........................
<img src="<%=n%>.jpg">
.............................................
这样就是显示1.jpg,2,jpg........................................了
----------------解决方案--------------------------------------------------------
为什么显示的是叉叉???需要将放图片的文件夹连接上吗?
----------------解决方案--------------------------------------------------------
那是当然了,图片不会自己生成啊!没有东西是没有办法显示的?
[此贴子已经被作者于2004-11-29 09:20:05编辑过]
----------------解决方案--------------------------------------------------------
多位数字要怎样控制图片数和位数一致?
比如人数为52时,要怎样使输出是图片数字5和2?
----------------解决方案--------------------------------------------------------
除以10,然后取整和取余,就有那两个数了,然后连着显示图片就是了,如果是两位以上,就继续这样就可以了
----------------解决方案--------------------------------------------------------