servlet中调用一个后台方法,返回一个字符串
把值存在session里,跳转到Ok.jsprePath = Shapshot.shapshot(srcUrl, method);
System.out.println(rePath);session.setAttribute("repath", rePath);
System.out.println("servlet——"+session.getAttribute("repath"));response.sendRedirect("ok.jsp");输出结果为
null
servlet——null再次访问时,返回的是上一次的rePath
地址1
servlet——地址1

解决方案 »

  1.   

    很明显是你方法shapshot(srcUrl, method);第一次返回null,第二次返回地址1,贴这点代码没什么问题啊,不明白你要实现什么需求,你所谓的“显示为上一次的值”是什么意思
      

  2.   

    很明显是你方法shapshot(srcUrl, method);第一次返回null,第二次返回地址1,贴这点代码没什么问题啊,不明白你要实现什么需求,你所谓的“显示为上一次的值”是什么意思
      

  3.   

    以前做练习的时候也碰到过类似问题,就是显示验证码的问题,后来通过ajax解决,就是异步和同步的问题,不知道lz是什么情况。
      

  4.   


    就是这类似的情况
    只能用ajax等解决么?
      

  5.   

    是异步同步问题?,那试试改成ajax同步
    /**
     * 设置AJAX同步
     */
    $.ajaxSetup({ 
        async : false 
    }); 
      

  6.   

    遇到过类似问题,不要用重定向啊,直接跳转!response.sendRedirect("ok.jsp");
      

  7.   

    public String doPath(HttpServletRequest request,
    final HttpServletResponse response) throws ServletException,
    IOException {
    return rePath;
    }public void service(HttpServletRequest request,
    final HttpServletResponse response) throws ServletException,
    IOException {
    String rePath = doPath(request, response);
    response.getWriter().write(rePath); }
    最后采取的方法