Arrays 字符串数组和会话
我正在处理一个严重的问题,似乎找不到合乎逻辑的解决办法。 来了。 我的代码(jsp文件)中有一个字符串数组。我想在同一页中传递数组,我曾想过将数组设置为会话,并在稍后的代码中再次调用它,但似乎无法将会话(使用get.Attribute)设置为数组。更具体地说,下面的代码可能会帮助您Arrays 字符串数组和会话,arrays,string,jsp,Arrays,String,Jsp,我正在处理一个严重的问题,似乎找不到合乎逻辑的解决办法。 来了。 我的代码(jsp文件)中有一个字符串数组。我想在同一页中传递数组,我曾想过将数组设置为会话,并在稍后的代码中再次调用它,但似乎无法将会话(使用get.Attribute)设置为数组。更具体地说,下面的代码可能会帮助您 while (onomaq.next()) { String onomatemp = onomaq.getString("one
while (onomaq.next()) {
String onomatemp = onomaq.getString("one1");
String[] onoma = onomatemp.split(" ");
out.println(onoma[2]);
session.setAttribute("onoma", onoma);
}
} catch (Exception e) {
System.out.println("SQL Exception: " + e.toString());
}
%>
<%
try{
Object o = session.getAttribute("onoma");
String k=o.toString();
String[] name=k.split(",");
out.println(name[1]);
}
catch (Exception e)
{
System.out.println("SQL Exception: " + e.toString());
}
while(onomaq.next()){
字符串onomatemp=onomaq.getString(“one1”);
字符串[]onoma=onomatemp.split(“”);
out.println(onoma[2]);
session.setAttribute(“onoma”,onoma);
}
}捕获(例外e){
System.out.println(“SQL异常:+e.toString());
}
%>
从会话中获取数组对象后,不要对其调用toString()
,只需将对象引用转换为数组(因为对象是数组)并使用它即可
这意味着,替换此代码:
Object o = session.getAttribute("onoma");
String k=o.toString();
String[] name=k.split(",");
与
p、 在美国,toString()
的目的与您似乎期望的有所不同。请参见。在从会话中获取数组对象后,不要调用数组对象上的toString()
,只需将对象引用强制转换为数组(因为对象是数组)并使用它即可
这意味着,替换此代码:
Object o = session.getAttribute("onoma");
String k=o.toString();
String[] name=k.split(",");
与
p、 在美国,toString()
的目的与您似乎期望的有所不同。看
然后在循环中运行它以检索。例如:
for(int i = 0; i < expected_array. length; i++)
{
String strings = expected_array[i] ;
}
for(int i=0;i
然后在循环中运行它以检索。例如:
for(int i = 0; i < expected_array. length; i++)
{
String strings = expected_array[i] ;
}
for(int i=0;i
用可读代码修复帖子…用可读代码修复帖子。。。