如何实现jsp和javascript变量存取?高分放送!

yujiabian 2005-07-11 03:44:05
我在jsp页面中使用了别人的一个js文件,里面实现了标签页的可定义函数,现在我想实现在tab页切换后,我在其中某一个tab页下进入编辑界面后,完成编辑后仍然能够定位到该标签页?如何实现,请各位大虾指教,最好有详细过程!急啊!
...全文
566 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
yujiabian 2005-08-29
  • 打赏
  • 举报
回复
结贴了!不过答案有点让我失望。。。。。
Goal3 2005-07-12
  • 打赏
  • 举报
回复
放在session里保存当前page. 如果是struts的话,我记得有是可以同时支持多表单页面提交
<input type="hidden" name="page">
<script>
session.setAttribute("page", page);
String page = (String)session.getAttribute("page");

hcom 2005-07-12
  • 打赏
  • 举报
回复
up
pcno1 2005-07-12
  • 打赏
  • 举报
回复
不知道。UP!
hui_feng 2005-07-12
  • 打赏
  • 举报
回复
学习学习.帮你顶一下......
飞翔的大麦茬 2005-07-12
  • 打赏
  • 举报
回复
把正在编辑的tab做个标识把值存入session,然后再把值放到tab的javascript中
这里应该先判断变量是否为空,为空则默认定位到第一个tab
var tab = <%=tag%> ;
if(tab ==""){

}
我对那段tab的javascript不熟,也没法说的详细:)
yujiabian 2005-07-12
  • 打赏
  • 举报
回复
javascript里面也能使用session?
yujiabian 2005-07-11
  • 打赏
  • 举报
回复
我是不是可以把hidden域通过session保存起来?获取session保存的hidden域值之后,又怎么传回js中改变显示?大虾们最好有代码说明
off_line 2005-07-11
  • 打赏
  • 举报
回复
不同页面间的javasrcipt 变量不能通信吧?
建议你利用页面或者表单变量来完成。
例如
<input type="hidden" name="page">
<script>
....
....
最后 document.form.page.value = xxx;
</script>
hongke1490 2005-07-11
  • 打赏
  • 举报
回复
程序没看明白,但这个问题我可以说两句:
JavaScript调用Jsp的变量很简单,这样就可以了:
<script>
alert('<%=Name%>');
</script>
Jsp要调用JavaScript的变量必须先提交服务器,否则服务器端不可能知道你在网页上做什么?至于怎么提交服务器就不用我说了吧!呵呵
yujiabian 2005-07-11
  • 打赏
  • 举报
回复
//js如下:
var lasttabid;
function TabBox(tabname,type){
var tabbox=this;
this.tabname=tabname;
this.lasttab=1;
this.tabarray=new Array()
this.tabPad=null;

//----保存tab项目数祖----
this.item=function(tabid,caption,dis){
this.tabid=tabid
this.caption=caption
this.dis=dis
}

//----添加tab项目----
this.addtab=function(tabid,caption,dis){
//alert(tabbox.tabarray.length)
tabbox.tabarray[tabbox.tabarray.length]=new tabbox.item(tabid,caption,dis)
}

//--程序初试化----
this.init=function(){
//alert(tabbox.tabname)
if (tabbox.tabarray.length==0) {alert("没有任何项目");return}
document.write("<div id='"+tabbox.tabname+"div'>")
tabbox.tabPad=eval("document.all."+tabbox.tabname+"div")
var tbBoard=document.createElement("table")
tabbox.tabPad.insertAdjacentElement("beforeEnd",tbBoard);
tbBoard.style.cssText="border-collapse: collapse"
tbBoard.border="0"
tbBoard.cellSpacing="0"
tbBoard.cellPadding="0"
tbBoard.height="24"
tbBoard.width="100%"
trRow = tbBoard.insertRow(0)
trRow.height="3"

var tl=0
tbCell=trRow.insertCell(tl)
tbCell.id=tabbox.tabname+'_tabbar1'
tbCell.rowSpan="2"
tbCell.className="tbottom3"
tbCell.width="3"
tbCell.noWrap=true

tl++
tbCell=trRow.insertCell(tl)
tbCell.id=tabbox.tabname+'_tabtop1'
tbCell.noWrap=true

for (i=1;i<tabbox.tabarray.length;i++)
{
tl++
tbCell=trRow.insertCell(tl)
tbCell.id=tabbox.tabname+'_tabbar'+(i+1)
tbCell.rowSpan="2"
tbCell.className="tbottom"
tbCell.width="3"
tbCell.noWrap=true

tl++
tbCell=trRow.insertCell(tl)
tbCell.id=tabbox.tabname+'_tabtop'+(i+1)
tbCell.noWrap=true
}

tl++
tbCell=trRow.insertCell(tl)
tbCell.id=tabbox.tabname+'_tabbar'+(tabbox.tabarray.length+1)
tbCell.rowSpan="2"
tbCell.className="tbottom2"
tbCell.width="3"
tbCell.noWrap=true

tl++
tbCell=trRow.insertCell(tl)
tbCell.rowSpan="2"
tbCell.width="100%"
tbCell.noWrap=true
tbCell.style.cssText="border-bottom:1px #000000 solid;"
//alert(tbBoard.cells.length)
trRow = tbBoard.insertRow(1)
for (i=0;i<tabbox.tabarray.length;i++)
{

tbCell=trRow.insertCell(i)
tbCell.id=tabbox.tabname+'_tabcon'+(i+1)
tbCell.className="lostfouce"
if (tabbox.tabarray[i].dis==1)
{
tbCell.innerHTML="<b>"+tabbox.tabarray[i].caption+" "+"</b>"
}
else
{
tbCell.innerHTML=tabbox.tabarray[i].caption+" "
}
tbCell.tabnum=i+1
tbCell.noWrap=true
tbCell.onclick=function()
{
tabbox.doclick(this.tabnum)
lasttabid=tabbox.lasttab
alert(lasttabid)
}
tbCell.onmouseover=function()
{

}
tbCell.onmouseout=function()
{
tabbox.doout(this)
}
}

}

this.inithidetab=function(num)
{

for (i=0;i<tabbox.tabarray.length;i++)
{
eval(tabbox.tabarray[i].tabid).style.display="none"
}
tabbox.doclick(1)
}
this.doclick=function(num,action){
lastbar1=eval(tabbox.tabname+"_tabbar"+this.lasttab)
nlasttab=this.lasttab+1
lastbar2=eval(tabbox.tabname+"_tabbar"+nlasttab)

tpbar1=eval(tabbox.tabname+"_tabbar"+1)
tpbar2=eval(tabbox.tabname+"_tabbar"+(tabbox.tabarray.length+1))

tabtop=eval(tabbox.tabname+"_tabtop"+this.lasttab)
tabcon=eval(tabbox.tabname+"_tabcon"+this.lasttab)
tabtop.className=""
tabcon.className="lostfouce"
//alert(lastbar2.className)
lastbar1.className='tbottom';
lastbar2.className='tbottom';
tpbar1.className='tbottom3';
tpbar2.className='tbottom2';
eval(tabbox.tabarray[this.lasttab-1].tabid).style.display="none"

lastbar1=eval(tabbox.tabname+"_tabbar"+num)
nnum=num+1
lastbar2=eval(tabbox.tabname+"_tabbar"+nnum)
tabtop=eval(tabbox.tabname+"_tabtop"+num)
tabcon=eval(tabbox.tabname+"_tabcon"+num)
lastbar1.className='tleft';
lastbar2.className='tright';
tabtop.className="ttop"
tabcon.className="getfouce"
//alert(tabbox.tabarray[num-1].tabid)
eval(tabbox.tabarray[num-1].tabid).style.display="block"

this.lasttab=num;
}


this.doover=function(obj){
if (obj.className=="lostfouce")
{
obj.className="lostfouce_over"
}

}

this.doout=function(obj){
if (obj.className=="lostfouce_over")
{
obj.className="lostfouce"
}

}
}

///jsp如下:(我使用的是Jdeveloper 10g)
<%@ taglib uri="http://xmlns.oracle.com/adf/ui/jsp/adftags" prefix="adf"%>
<adf:uimodelreference model="execution_specattListUIModel" /><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ page contentType="text/html;charset=GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title><bean:message key="execution.specattlist.caption" /></title>
<link href="../css/site.css" rel="stylesheet" type="text/css" media="screen">
<link href="../css/tabstyle.css" rel="stylesheet" type="text/css" media="screen">
<script src="../jscript/publicfunction.js" type="text/javascript"></script>
<script src="../jscript/tabclass.js" type="text/javascript"></script>
</head>
<body>
<jsp:include page="../system/first.jsp"/>
<html:errors/>
<table width="100%" border="0">
<tr class="titlecolor">
<td height="25" background="../images/titlebgimg.gif">   <bean:message key="execution.specattlist.caption"/></td>
</table>
<script>
var tabbox1=new TabBox("tab1")
tabbox1.addtab("p1","查询",0)
tabbox1.addtab("p2","专题调度列表")
</script>
<table border="0" style="border-collapse: collapse" bordercolor="#808080" cellpadding="0" >
<tr><td>
<script>
tabbox1.init()
</script>
</td>
</tr>
<tr width="300"><td bgcolor="#FFFFFF" style="border:1px #000000 solid;border-top:none" nowrap>
<table id=p1>
</br>
<tr><td>

</td></tr>
</table>
<table id=p2>
</br>
<tr><td>
<jsp:include page="../system/listview.jsp">
<jsp:param name="whichview" value="TDSaSpecialattemperView1"/>
<jsp:param name="targetPageName" value="specattList.do"/>
<jsp:param name="createforward" value="Create"/>
<jsp:param name="editforward" value="Edit"/>
</jsp:include>
</td></tr>
</table>
</td></tr>
<script>
tabbox1.inithidetab()
</script>
</table>
<jsp:include page="../system/last.jsp"/>
</body>
</html>

DanielYWoo 2005-07-11
  • 打赏
  • 举报
回复
看了你的标题,再看内容实在是看晕了。
你的JavaScript切换tab页的函数应该有参数的吧?把它贴出来
zjjsgwm 2005-07-11
  • 打赏
  • 举报
回复
....我想应该是用隐藏域是存参数吧。javaScript取得参数定位。
yujiabian 2005-07-11
  • 打赏
  • 举报
回复
晕!就是利用在jsp页面中使用了javascript程序来实现tab页效果,但是刷新后程序不能正确定位到最后一次访问的tab页上,而跑到第一个tab页上,这下说明白了吧?
  • 打赏
  • 举报
回复
没看明白说的是什么。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧