如何能迅速地返回前一个页面?

GFox 2002-08-16 04:12:51
例如 a.jsp 连接到 b.jsp ,我想在看完 b.jsp 后按返回按钮返回到 a.jsp。
我是用
javascript:window.history.back(1)来返回的结果很慢。

个人觉得是因为返回时刷新了 a.jsp, 而 a.jsp 是要运行好久才显示的,这样返回就变得很慢了。

a.jsp是一定要花很长时间来运算的了(30s~1分钟),要是返回时刷新了的话,也要这么长时间,太不合理了

各位有没有什么方法是返回时不刷新了 a.jsp 的呢或者是其它的能快速返回的方法也可以啊

谢谢各位了^_^
...全文
564 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
bhr 2002-08-19
  • 打赏
  • 举报
回复
具体怎么实现的,说来听听!
GFox 2002-08-19
  • 打赏
  • 举报
回复
嗯,我的问题已经解决了,是缓存方面的问题。

谢谢各位了^_^
Reve 2002-08-18
  • 打赏
  • 举报
回复
补充一下:上边的代码中的ServletUtilities.headWithTitle应该删去才可以通过。
Reve 2002-08-18
  • 打赏
  • 举报
回复
我认为是浏览器后退时,回对后退的页面(特别是CGI生成的)发送一个是否叶面已经过期的请求,你的机器收到浏览器的刷新请求,认为过期了,便重新执行相应的jsp叶面,但可能是你这个叶面需要的执行时间较长,从而使得要等30多秒,可以让上述的页面返回一个最后更改的时间为让一次执行的时候的时间,这样会使得后退回快一点,一个书上的例子:
package mine;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Example using servlet initialization and the
* getLastModified method.
*/
public class LotteryNumbers extends HttpServlet {
private long modTime;
private int[] numbers = new int[10];
/** The init method is called only when the servlet
* is first loaded, before the first request
* is processed.
*/
public void init() throws ServletException {
// Round to nearest second (ie 1000 milliseconds)
modTime = System.currentTimeMillis()/1000*1000;
for(int i=0; i<numbers.length; i++) {
numbers[i] = randomNum();
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Your Lottery Numbers";
out.println(ServletUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n" +
"<B>Based upon extensive research of " +
"astro-illogical trends, psychic farces, " +
"and detailed statistical claptrap, " +
"we have chosen the " + numbers.length +
" best lottery numbers for you.</B>" +
"<OL>");
for(int i=0; i<numbers.length; i++) {
out.println(" <LI>" + numbers[i]);
}
out.println("</OL>" +
"</BODY></HTML>");
}
/** The standard service method compares this date
* against any date specified in the If-Modified-Since
* request header. If the getLastModified date is
* later, or if there is no If-Modified-Since header,
* the doGet method is called normally. But if the
* getLastModified date is the same or earlier,
* the service method sends back a 304 (Not Modified)
* response, and does <B>not</B> call doGet.
* The browser should use its cached version of
* the page in such a case.
*/
public long getLastModified(HttpServletRequest request) {
return(modTime);
}
// A random int from 0 to 99.
private int randomNum() {
return((int)(Math.random() * 100));
}
}
主要的函数在于:
public long getLastModified(HttpServletRequest request) {
return(modTime);
}
只是后退也会看到随机数并没有更改。
SAsura 2002-08-18
  • 打赏
  • 举报
回复
jsp页面的过期时间好像是0吧,ie每次进入这个页面必然会刷新,不会从缓存中拿的,想办法优化你的响应时间吧,如果是统计结果你可以把他存起来下回再用啊
zzz654321 2002-08-18
  • 打赏
  • 举报
回复
哥们用重新定向的方法很好: response.sendRedirect(a.jsp);

asset 2002-08-17
  • 打赏
  • 举报
回复
优化原页面的数据访问,缩短页面响应时间。
Brain 2002-08-17
  • 打赏
  • 举报
回复
比较大的数据?你又要求比较快。
你重新显示A的时候需要从资源(例如数据库)中读取吗?

如果是,有一个办法是放大数据放到session中,当然要大大牺牲服务器资源了,看你权衡的结果。


GFox 2002-08-17
  • 打赏
  • 举报
回复
没有人有好办法吗?
GFox 2002-08-17
  • 打赏
  • 举报
回复
to Brain(无缺公子)

这个方法我也想过,还可以的,不过我想啊,为什么返回时一定要重新运行A.jsp啊?我明明已经运行过一次而且数据也传了过来了啊,所以我才想直接退回去就是了,所以才想问一下有没有不刷新的返回方法,谢谢:)

to asset(书恒)

这个是根本,但目前还不能做到
GFox 2002-08-16
  • 打赏
  • 举报
回复
to: bhr(追风)

应该没有:)

to: upc_chenli(chenli)

是比较大的数据啊,唉~~
upc_chenli 2002-08-16
  • 打赏
  • 举报
回复
你的数据是不是很多啊?
怎么会那么久?
bhr 2002-08-16
  • 打赏
  • 举报
回复
你是不是在jsp中设置了清楚缓存?
GFox 2002-08-16
  • 打赏
  • 举报
回复
to 7(Nomad)

这样还不是等于 <a href="a.jsp">返回</a>

这样会刷新的吧?

我试试看……
GFox 2002-08-16
  • 打赏
  • 举报
回复
history.go(-1)应该和在IE里点“返回”的确是一样的

我要的是不刷新页面的。

我在IE里点“返回”也要40秒

我觉得主要原因是刷新了页面,有没有不的?
7 2002-08-16
  • 打赏
  • 举报
回复

String request_url=request.getHeader("Referer");
out.print("<a href="+request_url+">返回</a>");
bhr 2002-08-16
  • 打赏
  • 举报
回复
history.go(-1)应该和在IE里点“返回”是一样的.
你确认在IE里点“返回”就比这样快?
GFox 2002-08-16
  • 打赏
  • 举报
回复
to 7(Nomad)

能不能不在jsp里面转?我需要在IE里让人家点“返回”我才返回啊:)
GFox 2002-08-16
  • 打赏
  • 举报
回复
to:wjmmml(笑着悲伤)

javascript:history.back()不快啊,我返回要40秒才返回啊,痛苦啊
7 2002-08-16
  • 打赏
  • 举报
回复
// 重定向页面
String request_url=request.getHeader("Referer");
response.sendRedirect(request_url);
return;
加载更多回复(7)

62,614

社区成员

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

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