动态导航,经点击的值存入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);
}