如何更新会话属性 [英] How to update session attribute

查看:83
本文介绍了如何更新会话属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保存了一些会话属性.我有一个jsp页面,通过该页面可以调用servlet.该servlet更新了一个会话变量,但是在我的jsp.Pls帮助中看不到这些更改的反映.

I have some session attributes being saved. I have a jsp page on which a call to a servlet is made through. This servlet updates one of the session variable but I am not able to see the reflection of these changes in my jsp.Pls help.

在我的servlet中

In My servlet

    List<DriverList> abc = dao.getABC();
    request.getSession().removeAttribute("abc");
    request.getSession().setAttribute("abc", abc);

在我的jsp中

function update()
{
    var url = "updateServlet";
    var req = $.ajax({
    type: 'GET',
    url: url,
    cache: false,
    type: "GET",
    success: function()
    {
        latlng = [];
        latlng = [<c:forEach var="test" items="${abc}">
                     [<c:out value="${test.latitude}"/>,<c:out value="${test.longitude}"/>,"<c:out value= "${test.name}" />",<c:out value="${test.cellNo}"/>],
                 </c:forEach> ];

    },
    error: function (status) {
         }

    });

}  

${abc}的值与以前相同.如何获得新值?

The value of ${abc} is same as before. How to get the new value ?

确切流量-

  1. ,当设置了sessionAttribute时,称为登录servlet abc的值.

  1. when login servlet is called abc value as sessionAttribute is set.

现在,这将重定向到base.jsp.我是第一次使用abc.现在,每隔30秒就会调用此update()函数.此更新功能通过ajax调用servlet,其中的会话属性abc被更新.

Now this redirects to base.jsp. I use abc for the first time. Now after every 30 seconds this update() function is called. This update function calls a servlet through ajax where the session attribute abc is updated.

在ajax请求的成功功能中,我想使用这个新的abc值,但又要获取旧的abc值.

In the success function of ajax request I want to use this new abc value but getting the old one again.

推荐答案

要在JSP中访问abc变量,请尝试:

To access the abc variable in the JSP try:

${sessionScope.abc}

还请注意,设置前删除通常是多余的.所以:

Also note that removing before setting is usually redundant. So:

request.getSession().removeAttribute("abc");
request.getSession().setAttribute("abc", abc);

可以简单地成为:

request.getSession().setAttribute("abc", abc);

这篇关于如何更新会话属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆