标题:jsp+session拼图游戏原理分析
摘要: 通过排字游戏学习理解session对象
难度:
see.jsp
move.jsp
作者:吕海鹏
来自:it学习网原创
更新日志:
参考文档:
致谢:
讨论网址: http://bbs.deepteach.com
标签(Tags):jsp+session
摘要: 通过排字游戏学习理解session对象
难度:
通过排字游戏学习理解session对象
index..jsp
<% int [][] ges= new int[3][3]; int shu=0; for (int h=0;h<3;h++) { for (int l=0;l<3;l++) { ges[h][l]=shu; shu++; } } for(int ci=0;ci<10;ci++) { int h1=(int)(3*Math.random()); int l1=(int)(3*Math.random()); int h2=(int)(3*Math.random()); int l2=(int)(3*Math.random()); int linshi=ges[h1][l1]; ges[h1][l1]=ges[h2][l2]; ges[h2][l2]=linshi; } session.setAttribute("ges",ges); response.sendRedirect("see.jsp"); %> |
see.jsp
<% int ges[][]=new int[3][3]; ges=(int[][])session.getAttribute("ges"); %> <table width="300" align="center" border="1" height="300"> <% for (int h=0;h<3;h++) { %> <tr> <% for (int l=0;l<3;l++) { %> <td align="center"> <% if (ges[h][l]!=0){ %> <a href="move.jsp?h=<%=h%>&l=<%=l%>"> <font style="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=new int[3][3]; ges=(int[][])session.getAttribute("ges"); int h=Integer.parseInt(request.getParameter("h")); int l=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