标题:jsp+session拼图游戏原理分析
摘要: 通过排字游戏学习理解session对象
难度:
see.jsp
move.jsp
作者:吕海鹏
来自:it学习网原创
更新日志:
参考文档:
致谢:
讨论网址: http://bbs.deepteach.com
标签(Tags):jsp+session
摘要: 通过排字游戏学习理解session对象
难度:
通过排字游戏学习理解session对象
index..jsp
<% int[][]ges=newint[3][3]; intshu=0; for(inth=0;h<3;h++) { for(intl=0;l<3;l++) { ges[h][l]=shu; shu++; } } for(intci=0;ci<10;ci++) { inth1=(int)(3*Math.random()); intl1=(int)(3*Math.random()); inth2=(int)(3*Math.random()); intl2=(int)(3*Math.random()); intlinshi=ges[h1][l1]; ges[h1][l1]=ges[h2][l2]; ges[h2][l2]=linshi; } session.setAttribute("ges",ges); response.sendRedirect("see.jsp"); %> |
see.jsp
<% intges[][]=newint[3][3]; ges=(int[][])session.getAttribute("ges"); %> <tablewidth="300"align="center"border="1"height="300"> <% for(inth=0;h<3;h++) { %> <tr> <% for(intl=0;l<3;l++) { %> <tdalign="center"> <% if(ges[h][l]!=0){ %> <ahref="move.jsp?h=<%=h%>&l=<%=l%>"> <fontstyle="FONT-WEIGHT:bold;FONT-SIZE:50px;COLOR:#FF0000;;FONT-FAMILY:Georgia"> <b><i><%=ges[h][l]%></b></i> </font> </a> <% }else{ %> <%}%> </td> <% } %> </tr> <% } %> </table> |
move.jsp
<% int[][]ges=newint[3][3]; ges=(int[][])session.getAttribute("ges"); inth=Integer.parseInt(request.getParameter("h")); intl=Integer.parseInt(request.getParameter("l")); if((h>0)&&(ges[h-1][l]==0)) { ges[h-1][l]=ges[h][l]; ges[h][l]=0; } if(h<2&&ges[h+1][l]==0) { ges[h+1][l]=ges[h][l]; ges[h][l]=0; } if(l>0&&ges[h][l-1]==0) { ges[h][l-1]=ges[h][l]; ges[h][l]=0; } if(l<2&&ges[h][l+1]==0) { ges[h][l+1]=ges[h][l]; ges[h][l]=0; } session.setAttribute("ges",ges); response.sendRedirect("see.jsp"); %> |
作者:吕海鹏
来自:it学习网原创
更新日志:
参考文档:
致谢:
讨论网址: http://bbs.deepteach.com
标签(Tags):jsp+session