title: How can i send an array of string from servlet to jsp and recieve it in jsp
body: <p>My Servlet Code is</p>
  
  <pre><code>package DBCon;
  
  import java.io.*;
  import java.net.*;
  import java.util.ArrayList;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  /**
   *
   * @author Nayan
   */
  public class loadCourseId extends HttpServlet {
  
      /** 
      * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt; methods.
      * @param request servlet request
      * @param response servlet response
      */
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          response.setContentType("text/html;charset=UTF-8");
          PrintWriter out = response.getWriter();
          ArrayList ar1=new ArrayList();
          ArrayList ar2=new ArrayList();
          int i;
          i=0;
  
          try
          {
              Class.forName("com.mysql.jdbc.Driver").newInstance();
              Connection con=DriverManager.getConnection("jdbc:mysql://localhost/online_exam?"+"user=root&amp;password=pass");
              Statement stmt=con.createStatement();
              ResultSet rs=stmt.executeQuery("select * from course");
  
              while(rs.next())
              {
                  ar1.add(rs.getString(1));
                  ar2.add(rs.getString(2));
              }
              request.getSession().setAttribute("CourseID", ar1);
              request.getSession().setAttribute("CourseName", ar2);
              RequestDispatcher requestDispatcher=getServletContext().getRequestDispatcher("http://localhost:8080/ONLINE_EXAM/removeCourse.jsp");
              requestDispatcher.forward(request,response);
  
  
          }
           catch(Exception e) { 
              out.println("&lt;h1&gt;"+e.getStackTrace()+"&lt;/h1&gt;");
          }
      } 
  
      // &lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."&gt;
      /** 
      * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
      * @param request servlet request
      * @param response servlet response
      */
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          processRequest(request, response);
      } 
  
      /** 
      * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
      * @param request servlet request
      * @param response servlet response
      */
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /** 
      * Returns a short description of the servlet.
      */
      public String getServletInfo() {
          return "Short description";
      }
      // &lt;/editor-fold&gt;
  }
  </code></pre>
  
  <p>And Jsp Code is</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@page import="javax.servlet.*"%&gt;
  &lt;%@ page import="java.util.ArrayList.*" %&gt;
  &lt;%@ page import="java.sql.*;" %&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript" language="Javascript" &gt;
              window.onload=function LoadCombo()
              {
  
                 window.action="loadCourseId.do";
                 ArrayList cd=new ArrayList();
                 cd.add(request.getSession().getAttribute("CourseID"));
                 if(cd.isEmpty()==false)
                 {
                     for(int i=0;i&lt;cd.size();i++)
                     {
                         var newOpt = cid.appendChild(document.createElement('option'));
                         newOpt.text = cd.get(i);
  
                     }
                 }
                 else
                 {
                     alert("Course table is empty")
                 }
  
              }
  
          &lt;/script&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Remove Course&lt;/title&gt;
  &lt;style type="text/css"&gt;
              &lt;!--
  body {
      background-color: #FFCCFF;
  }
  .style1 {
      color: #0066FF;
      font-weight: bold;
  }
  .style2 {font-size: 18px}
  .style17 {  font-family: "Monotype Corsiva";
      font-size: 24px;
      font-weight: bold;
      font-style: italic;
      color: #6633CC;
  }
  .style19 {color: #000099}
  .style21 {color: #000099; font-weight: bold; }
  --&gt;
          &lt;/style&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;jsp:include page="Log_Admin.jsp"/&gt;&lt;br/&gt;
          &lt;form action="" method="post" name="form1" id="form1" &gt;
          &lt;table width="46%" height="43" border="3" bgcolor="##CCCC99" align="center"&gt;
              &lt;tr&gt;
                  &lt;td width="85%" align="center" bgcolor="##CCCC99"&gt;&lt;label&gt;&lt;span class="style17"&gt;Course Information&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
              &lt;/tr&gt;
  
              &lt;tr&gt;&lt;td&gt;
                  &lt;table width="666" height="207" border="0" align="center" bordercolor="#F0F0F0" bgcolor="#CCCC99" &gt;
                      &lt;tr&gt;
                          &lt;td width="186" height="46" align="left"&gt;&lt;div align="left"&gt;&lt;span class="style19"&gt;
                          &lt;label&gt;&lt;strong&gt;Course ID&lt;/strong&gt;&lt;/label&gt;
                          &lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
  
                          &lt;td&gt;&lt;label&gt;
                          &lt;select name="cid" size="1" id="cid" align="left"&gt;
  
  
                          &lt;/select&gt;
                          &lt;/label&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td height="53" align="left"&gt;&lt;div align="left"&gt;&lt;label&gt;&lt;span class="style21"&gt;Course Name&lt;/span&gt;&lt;/label&gt;&lt;/div&gt;&lt;/td&gt;
                          &lt;td align="left"&gt;&lt;input name="cname" type="text" id="cname" size="50" maxlength="50" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
  
                      &lt;tr&gt;
                          &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/td&gt;
                          &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;input name="save" type="submit" id="save" value="Save" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
                          &lt;input name="reset" type="reset" id="reset" value="Reset" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/td&gt;&lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Bt by writing this code i am not able to add item CourseId to the combobox cid. Can you say me where is the problem? Thanks.</p>