如果我在会话中有值,我需要在会话中获取所有值,如
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>");
}
}
答案 0 :(得分:2)
public class ConcreteImplementation : AbstractBaseClass<AnotherConcreteImplementation>
{
public override void Create(AnotherConcreteImplementation param1) // Works because TDerivedClass = AnotherConcreteImplementation
{
...
}
}
这段代码也很完美 感谢火花回复@karim mohsen
答案 1 :(得分:1)
Enumeration<String> attributes = request.getSession().getAttributeNames();
while (attributes.hasMoreElements()) {
String attribute = attributes.nextElement();
System.out.println(attribute+" : "+request.getSession().getAttribute(attribute));
}
答案 2 :(得分:1)
$ which aws
/home/enanone/.local/bin/aws
此代码适用于jsp
答案 3 :(得分:0)
Enumeration attributeNames = session.getAttributeNames();
while (attributeNames.hasMoreElements()) {
String temp= attributeNames.nextElement();
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>");
}
}
答案 4 :(得分:0)
本守则在JSP
中完成 emun = session.getAttributeNames(); //获取会话%&gt;中的所有属性名称答案 5 :(得分:0)
如果要获取所有带有Key及其值的Session对象,那么此代码对您来说很好用。
.gitignore
输出
Enumeration keys = session.getAttributeNames();
while (keys.hasMoreElements())
{
String key = (String)keys.nextElement();
out.println(key + ": " + session.getValue(key) + "<br>");
}