【问题标题】:string cannot be converted to ArrayList<String> when getting as request.getParameter(" ")获取为 request.getParameter(" ") 时,字符串无法转换为 ArrayList<String>
【发布时间】:2020-01-01 22:59:06
【问题描述】:

从另一个jsp获取jsp中的列表值作为request.getParameter("")

a.jsp

List<String> abc = 
 (ArrayList<String>)request.getAttribute("studentsrollno");// got 
  studentsrollno from servlet by request.setAttribute();

   <form action="b.jsp" method="post">
       <input type="hidden" name="rollno" value="<%=abc%>"/>

            <input type="submit">
   </form>

b.jsp

         <%
   List<String> a2 = (ArrayList<String>) request.getParameter("rollno");// 
 getting error string cannot be converted to ArrayList<String> // How can I 
 display data rollno here ?

  // Iterator<String> itr = a2.iterator();

             %>

提前非常感谢

【问题讨论】:

    标签: java string list jsp arraylist


    【解决方案1】:

    您可以将值作为数组检索:

    String[] vals = request.getParameterValues("rollno");
    

    这些值应该作为单独的表单参数发出:

    <c:foreach items="${abc}" var="item">
        <input type="hidden" name="rollno" value="${fn:escapeXml(item)}" />
    </c:foreach>
    

    【讨论】:

    • @Tom 你不应该使用 scriptlet,所以跳过这部分直接使用 JSTL。
    猜你喜欢
    • 2014-05-16
    • 1970-01-01
    • 2013-12-05
    • 2012-08-22
    • 2013-11-19
    • 2021-07-12
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多