如何获取所有会话值和名称? [英] How to get all Session values and names?

查看:71
本文介绍了如何获取所有会话值和名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在一个会话中有值,而我需要在一个会话中获取所有值,例如

if i have values in a session and i need to get all the values in a session like

String[] name = request.getParameterValues("values");
HttpSession session = request.getSession();

for(String temp:name)
{
    if(temp.equalsIgnoreCase("a"))
    {
        session.setAttribute("a", temp);
        out.println("a is Running<br>");
    }

    if(temp.equalsIgnoreCase("b"))
    {
        session.setAttribute("b", temp);
        out.println("b is Running<br>");
    }

    if(temp.equalsIgnoreCase("c"))
    {
        session.setAttribute("c", temp);
        out.println("c is Running<br>");
    }

    if(temp.equalsIgnoreCase("d"))
    {
        session.setAttribute("d", temp);
        out.println("d is Running<br>");
    }

    if(temp.equalsIgnoreCase("e"))
    {
        session.setAttribute("e", temp);
        out.println("e is Running<br>");
    }

    if(temp.equalsIgnoreCase("f"))
    {
        session.setAttribute("f", temp);
        out.println("f is Running<br>");
    }
}

  • 如果我将一组复选框值设置为字符串.我设置所有 在.jsp中选择到会话对象的值.我需要 只检索jsp中选定的值,这些值保存在 以上代码.
    • if I get a set of checkbox values to a string. Im setting all the values which are selected in a .jsp to a session object. I need to retrieve only the selected values in a jsp which are saved in the above code.
    • 推荐答案

      Enumeration<String> attributes = request.getSession().getAttributeNames();
      while (attributes.hasMoreElements()) {
          String attribute = (String) attributes.nextElement();
          System.out.println(attribute+" : "+request.getSession().getAttribute(attribute));
      }
      

      这篇关于如何获取所有会话值和名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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