问题描述: 双击列表后,可进入该项的FORM表单修改,同时有一个返回列表的按钮。[b]当点击按钮后,有时候不能按预想返回列表(出现乱跳现象)[/b]
代码:
[code="java"]private Href[] historyHrefs = new Href[10];
private void addHistoryHref(Href href) {
if (me == null)
me = this;
if (historyHrefs[0] == null) {
historyHrefs[0] = href;
return;
}
if (historyHrefs[0].path != null
&& historyHrefs[0].path.equals(href.path)) {
historyHrefs[0].query = href.query;
return;
}
if (historyHrefs[1] != null && historyHrefs[1].equals(href)) {
// 返回
for (int i = 0; i < historyHrefs.length - 1; i++) {
historyHrefs[i] = historyHrefs[i + 1];
}
historyHrefs[historyHrefs.length - 1] = null;
return;
}
// 加入
for (int i = historyHrefs.length - 1; i > 0; i--) {
historyHrefs[i] = historyHrefs[i - 1];
}
historyHrefs[0] = href;
for (Href historyHref : historyHrefs) {
}
}[/code]
此部分代码是对SESSION中的数组进行操作,保存URL。
请问:多人在线使用的时候会不会出现SESSION被改的情况,private Href[] historyHrefs = new Href[10];我使用了private ,这样也会出现共用现象吗?
[b]问题补充:[/b]
1楼兄弟,谢谢你回复,其实10个也用不上,因为我是返回上一级。例:在分页中,我的列表在30页,我点入一条记录修改后,如果不设置,返回后会在第1页。而我这样做的目的就是要那第30也的URL。而拿的时候我是指定拿historyHrefs[1],你看了算法就会发现。
[b]问题补充:[/b]
我最初和2楼的兄弟想法一样,但是没能想明白原因(大脑不听使唤),而且在本地测试中确实没有问题。
我这样写大家看看写么?
[code="java"]Href[] historyHrefs = (Href[]) request.getSession().getAttribute("parentUrl");[/code]
另补充问一个问题:
我这样做是通过parentUrl拿的,如果换成referer做会不会出现这种问题。