首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp菜初始值有关问题。跪求高手

2012-02-19 
jsp菜初始值问题。。跪求高手~当我选择了菜单的某项,并单击下一页跳转到的新的页面,菜单的状态又为默认的了。

jsp菜初始值问题。。跪求高手~
当我选择了菜单的某项,并单击下一页跳转到的新的页面,菜单的状态又为默认的了。我想保存上次的选择

代码如下,看着有点长,但不难:


<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.List"%>
<%@ page import="com.mes.server.webconsole.model.ClientVersion"%>
<%@ page import="java.io.IOException"%>
<%@ include file="/WEB-INF/pages/commons/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/WEB-INF/pages/commons/meta.jsp"%>

<style type="text/css">
<!--
body {
margin-left: 3px;
margin-top: 0px;
margin-right: 3px;
margin-bottom: 0px;
}

.STYLE1 {
color: #e1e2e3;
font-size: 12px;
}

.STYLE6 {
color: #000000;
font-size: 12;
}

.STYLE10 {
color: #000000;
font-size: 12px;
}

.STYLE19 {
color: #344b50;
font-size: 12px;
}

.STYLE21 {
font-size: 12px;
color: #3b6375;
}

.STYLE22 {
font-size: 12px;
color: #295568;
}

a:link {
text-decoration: none;
}

a:visited {
text-decoration: none;
}

a:hover {
text-decoration: none;
}

a:active {
text-decoration: none;
}
-->
</style>
<script>
var highlightcolor='#d5f4fe';
//此处clickcolor只能用win系统颜色代码才能成功,如果用#xxxxxx的代码就不行,还没搞清楚为什么:(
var clickcolor='#51b2f6';
function changeto(){
source=event.srcElement;
if (source.tagName=="TR"||source.tagName=="TABLE")
return;
while(source.tagName!="TD")
source=source.parentElement;
source=source.parentElement;
cs = source.children;
//alert(cs.length);
if (cs[1].style.backgroundColor!=highlightcolor&&source.id!="nc"&&cs[1].style.backgroundColor!=clickcolor)
for(i=0;i<cs.length;i++){
cs[i].style.backgroundColor=highlightcolor;
}
}

function changeback(){
if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="nc")
return
if (event.toElement!=source&&cs[1].style.backgroundColor!=clickcolor)
//source.style.backgroundColor=originalcolor
for(i=0;i<cs.length;i++){
cs[i].style.backgroundColor="";
}
}

function clickto(){
source=event.srcElement;
if (source.tagName=="TR"||source.tagName=="TABLE")
return;
while(source.tagName!="TD")
source=source.parentElement;
source=source.parentElement;
cs = source.children;
//alert(cs.length);
if (cs[1].style.backgroundColor!=clickcolor&&source.id!="nc")
for(i=0;i<cs.length;i++){
cs[i].style.backgroundColor=clickcolor;
}
else
for(i=0;i<cs.length;i++){
cs[i].style.backgroundColor="";
}
}

function del(path){

if(confirm("确认要卸载此客户端?")){

location.href="${ctx}/console.html?action=clientVersion&method=remove&path=" + path;
}

}

function copy(url){
window.clipboardData.setData('Text','http://'+window.location.host+url);
alert("复制成功");

}

function search(versionName){
location.href="${ctx}/console.html?action=clientVersion&method=list&versionName=" + versionName;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<%


String VN="";
try{
VN=request.getParameter("versionName");
}catch(Exception e){}
%>
<body>
<table width="100%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td height="30">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="24" bgcolor="#353c44">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="100%" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td width="6%" height="19" valign="bottom">
<div align="center">
<img src="images/tb.gif" width="14" height="14" />
</div>
</td>
<td width="94%" valign="bottom">
<span class="STYLE1"> 客户端版本管理</span>
</td>
</tr>
</table>
</td>
<td>
<div align="right">
<span class="STYLE1">查询:</span><select name="versionName" onchange="search(this.value)">
<option value="">所有</option>
<c:forEach items="${versionNames}" var="versionName">
<option value="${versionName }">${versionName }</option>
</c:forEach>
</select>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="STYLE1">&nbsp;&nbsp;<a href="#"
onClick="location.href='${ctx}/console.html?action=clientVersion&method=add'"><img
border="0" src="images/add.gif" width="10" height="10" />
<span class="STYLE1">添加</span>
</a> &nbsp;<!-- <img src="images/del.gif" width="10" height="10" /> 删除 &nbsp;&nbsp;<img src="images/edit.gif" width="10" height="10" /> 编辑 &nbsp;</span><span class="STYLE1">-->
&nbsp;</span>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="1"
bgcolor="#53c1d9" onmouseover="changeto()"
onmouseout="changeback()">
<tr>
<td width="15%" height="20" bgcolor="74d5ea" class="STYLE6">
<div align="center">
<span class="STYLE10">版本名称</span>
</div>
</td>
<td width="15%" height="20" bgcolor="74d5ea" class="STYLE6">
<div align="center">
<span class="STYLE10">版本号</span>
</div>
</td>
<td width="14%" height="20" bgcolor="74d5ea" class="STYLE6">


<div align="center">
<span class="STYLE10">大小</span>
</div>
</td>
<td width="16%" height="20" bgcolor="74d5ea" class="STYLE6">
<div align="center">
<span class="STYLE10">路径</span>
</div>
</td>
<td width="8%" height="20" bgcolor="74d5ea" class="STYLE6">
<div align="center">
<span class="STYLE10">操作</span>
</div>
</td>
</tr>
<%
int pageSum=0; //总页数
int currentPage=1; //当前页
int pageSize=5; //页面记录数
int totalSize=0; //总的记录数
int start=0; //当前页面开始的纪录索引
int end=0;
try{
currentPage=Integer.parseInt(request.getParameter("PN"));
}catch(Exception e){}

start=(currentPage-1)*pageSize;
List<ClientVersion> list=(List<ClientVersion>)request.getAttribute("result");
totalSize=list.size();
pageSum=(totalSize+pageSize-1)/pageSize;
System.out.println("totalSize pageSum pageSize currentPage");
System.out.println(totalSize+" "+pageSum+" "+pageSize+" "+currentPage);
if(totalSize<=currentPage*pageSize)
{
if(totalSize>0){
end=totalSize-1;
}
System.out.println("----->(1)");
}
else

end=start+pageSize-1;
System.out.println("----->(2)");
}
System.out.println("start: "+start+"end: "+end);
request.setAttribute("start", start); 
request.setAttribute("end", end); 
%>
<c:forEach items="${result}" var="clientVersion" begin="${start}" end="${end}">
<tr>
<td height="20" bgcolor="#FFFFFF" class="STYLE6">
<div align="center">
<span class="STYLE19">${clientVersion.versionName}</span>
</div>
</td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19">
<div align="center">
${clientVersion.version}
</div>
</td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19">
<div align="center">
${clientVersion.size}
</div>
</td>
<td height="20" bgcolor="#FFFFFF" class="STYLE19">
<div align="center">
<a href="${ctx}/${clientVersion.path}">${ctx}/${clientVersion.path}</a>
</div>
</td>


<td height="20" bgcolor="#FFFFFF">
<div align="center" class="STYLE21">


<a href="javascript:copy('${ctx}/${clientVersion.path}');">复制链接</a>
&nbsp;
<a href="javascript:del('${clientVersion.path}');">删除</a>
</div>
</td>
</tr>
</c:forEach>
</table>
</td>
</tr>
<tr>
<td height="30">
&nbsp;


</td>
</tr>
<tr>
<td align="center">共<%=pageSum%>页</td>
<td>
<%
if(currentPage==pageSum){
%>
当前是最后一页
<%
}else{
%>
当前是第<%=currentPage%>页
<%
}
%>
</td>
<td>&nbsp;</td>
<td>
<%
if(currentPage==1&&pageSum!=1){
%>
<a href="${ctx}/console.html?action=clientVersion&method=list&PN=<%=currentPage+1%>&versionName="+VN><font size="2px">下一页</font></a>
<%
}else if(currentPage==pageSum&&pageSum!=1){
%>
<a href="${ctx}/console.html?action=clientVersion&method=list&PN=<%=currentPage-1%>&versionName="+VN><font size="2px">上一页</font></a>
<%
}else if(pageSum!=1){
%>
<a href="${ctx}/console.html?action=clientVersion&method=list&PN=<%=currentPage-1%>&versionName="+VN><font size="2px">上一页|</font></a>
<a href="${ctx}/console.html?action=clientVersion&method=list&PN=<%=currentPage+1%>&versionName="+VN><font size="2px">下一页</font></a>
<%
}
%>
</td>
</tr>
</table>
</body>
</html>

[解决办法]
将你查询条件设置在request里传回去,在传回来 , 放到你input里就可以了

热点排行