[JSP ]如何把字串阵列从Object型态的变量取出?

楼主: mikevada (vada)   2016-02-22 19:45:12
因为有跨页传值的需求,目前想到用session.setAttribute来做,
但遇到一点困难,
page1.jsp
String h1=request.getParameter("g1");
String h2=request.getParameter("g2");
String h3=request.getParameter("g3");
String h4=request.getParameter("g4");
String h_count[]= new String[4];
for(int i=0;i<4;i++)
{
h_count[i]=request.getParameter("g"+(i+1));
out.println(h_count[i]);
}
out.println(h_count.length);
session.setAttribute("obj_h",h_count);
我把h_count这个字串阵列存到obj_h里,
page2.jsp
<%
Object obj=session.getAttribute("obj_h");
//把obj_h丢给obj,
out.println(obj.length);
会出现No variable length defined in class java.lang.Object的错误
%>
请问要怎么把obj_h从obj取出来啊?
作者: nhlsi (绿茶)   2016-02-22 19:49:00
String[] name= (String[]) session.getAttribute("obj_h")

Links booklink

Contact Us: admin [ a t ] ucptt.com