jsp+session拼图游戏原理分析

 标题: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{ 
            %> 
                &nbsp; 
            <%}%> 
        </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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值