如题吧。。。。。。。。
这个问题,困扰有段时间了。。。。
刚建的号。。。。分都用掉了。没有去挣。
[color=blue][b]假设SerlvetA和 SerlvetB ,SerlvetA提交到SerlvetB,然后刷新SerlvetB不会重复提交?[/b]
是这个意思吗?
[b]1、SerlvetB 提供一个 doGet方法, 该方法返回的是 一个等待页面。
2、SerlvetA提交给SerlvetB的doPost方法,doPost启动一个线程去做繁琐耗时的操作,然后调用doGet向浏览器输出等待页面。
2、该线程将任务执行的进度信息,存放在Session中。以备等待页面使用。
3、等待页面每隔几秒钟刷新一次,刷新的过程就是查询后台繁琐耗时的任务是否完成。
4、如果任务未完成,则依然返回等待页面;任务完成,则返回到下一个页面。
这样的话,如果你刷新SerlvetB, 会根据 后台操作完成的情况,如果未完成,则那个等待页面 , 而不会重复提交;如果完成,则会转向到其他页面。[/b]
试试吧,不是很难。关键是 ServletB的设计。[/color]
HttpServletResponse的sendRedirect()和RequestDispatcher 接口的forward()方法。
没明白是什么意思~~
这个不行吧,
要不然SERVLET提交后转向的页面再通过JS的 location.href?
或
感觉这效果还不如redirect呢
期待下面回答
在转后页面当中加一个变量,如果该变量等于什么值就不要提交。
换句话来说,就是在刷新之后,再提交的过程设一个卡。让它提交无效。
这个在JS里面才有效。
[b]给你个ServletB的简单雏形吧(仅供参考哦):[/b]
[code="java"]
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doWait(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 1、 提取有用的数据
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("username");
String password = request.getParameter("password");
HttpSession session = request.getSession(true);
session.setAttribute("done", "false");
// 2、启动一个线程,用于进行耗时的操作。线程的进展情况可以在Session的相关属性中得到
new HardworkThread(session,name,password).start();
// 3、进入等待操作中
doWait(request, response);
// 4、在doWait中会自动检测是否已完成任务
}
private void doWait(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
if ("true".equals(session.getAttribute("done")) ){
// 如果任务完成,则进行相应的页面跳转操作
} else {
// 如果任务未完成,则等待页面
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
// 注意这个等待页面,会自动刷新
response.setHeader("Refresh", "3");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<p>正在搜索数据库,请您等待....</p>");
out.println("</body></html>");
out.flush();
out.close();
}
}
[/code]
刷新不提交的话,那你就不要用换成就好了
用 iframe 试试吧