动态导航 保存状态

动态导航,经点击的值存入session

1、jsp页面:

 <div class="tabs"> 

          <a href="${ctx}/pages/Userbaseinfo/myIndex.login" οnclick="change(1)"><img id="id1" src="<%=basePath%>images/nav_01a.gif" width="120" height="37" /></a> 

          <a href="${ctx}/pages/Userbaseinfo/myIndex.login" οnclick="change(2)"><img id="id2" src="<%=basePath%>images/nav_02a.gif" width="120" height="37" /></a> 

          <a href="${ctx}/pages/Userbaseinfo/myIndex.login" οnclick="change(3)"><img id="id3" src="<%=basePath%>images/nav_03a.gif" width="120" height="37" /></a> 

          <a href="${ctx}/pages/Userbaseinfo/myIndex.login" οnclick="change(4)"><img id="id4" src="<%=basePath%>images/nav_04a.gif" width="120" height="37" /></a>

          <a href="${ctx}/pages/Userbaseinfo/myIndex.login" οnclick="change(5)"><img id="id5" src="<%=basePath%>images/nav_05a.gif" width="120" height="37" /></a> </div>

          <div class="clear"></div>

 

2、js :

 function change(index) {

$.post("${ctx}/pages/Userbaseinfo/setDaoHang.htm",{word:index},function(data) {

 //window.location = "${ctx}/pages/Userbaseinfo/myIndex.login";

     });

  }

  change_1();

  function change_1() {

$.post("${ctx}/pages/Userbaseinfo/getDaoHang.htm",null,function(data) {

//alert("d:"+data);

 $("#id"+data).attr("src","<%=basePath%>images/nav_0"+data+"b.gif");

     });

 }

 

3、后台

//控制导航

public void setDaoHang(HttpServletRequest request,HttpServletResponse response) {

HttpSession session = request.getSession();

String word = request.getParameter("word");

session.setAttribute("word", word);

System.out.println("word:"+word);

}

//获取导航值

public void getDaoHang(HttpServletRequest request,HttpServletResponse response) throws IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

HttpSession session = request.getSession();

String word = null;

if(session.getAttribute("word")!=null){

word = session.getAttribute("word").toString();

}

out.print(word);

System.out.println("word:"+word);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值