servlet 给 jsp 传数组 jsp里怎么接收?

2024-11-17 00:42:12
推荐回答(3个)
回答(1):

1.servlet:
request.setAttribute("objectname",objectvalue);
getServletContext().getRequestDispatcher(a.jsp).forward(request, response);

a.jsp
object=(objectname)request.getAttribute("objectname");
2.servlet:
request.setAttribute("objectname",object);
getServletContext().getRequestDispatcher(a.jsp).forward(request, response);

a.jsp:
aaa =(objectype)request.getAttribute("objectname");

回答(2):

getAttributet取值的时候强制类型转换成String[]类型的,前面再定义一个String[]的变量接收就行了
String[] str = (String[])request.getAttribute("abc");

回答(3):

jstl:




古老jsp内嵌java代码:

<%
String[] list= (String[])request.getAttribute("arrayName");

if(list!=null){
for(int i=0;irequest.setAttribute("index",i);
%>



<%

}

%>