Results 1 to 3 of 3

Thread: hwo to pass values from list box to servlet

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    39

    hwo to pass values from list box to servlet

    Hi
    I did use getValues method, but it does not work. Could you please help

    the error I did get is:

    java.lang.ArrayIndexOutOfBoundsException: 1
    email.DisplayMusicChiocesServlet.doPost(DisplayMusicChiocesServlet.java:57)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


    Code:
    package email;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    //import business.User;
    
    /**
     *
     * @author Omar
     */
    public class DisplayMusicChiocesServlet extends HttpServlet {
       
        /** 
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            String firstName =request.getParameter("firstName");
            String lastName =request.getParameter("lastName");
            
            
    
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
           
                String [] musictype  = request.getParameterValues("music");
                int i;
            for ( i = 0; i< musictype.length; i++) {
    
            }
    
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Servlet DisplayMusicChioces</title>");  
                out.println("</head>");
                out.println("<body>");
               
                out.println("<table style='border:2px solid red'>");
                out.println("<tr>");
                out.print("<td>");
                out.print("<h1>Thank you for joining our email list,</h1>" + firstName + musictype [i]+ lastName);
                out.println("</td>");
                 out.println("</tr>");
                
                out.println("<table>");
                out.println("</table>");
    
                out.println("</body>");
                out.println("</html>");
                out.close();
                
            } 
                
        @Override
            protected void doGet(
                HttpServletRequest request,
                HttpServletResponse  response)
               throws ServletException, IOException
            {
                doPost(request,response);
    
            }
        }

  2. #2
    New Member
    Join Date
    Feb 2011
    Posts
    1

    Re: hwo to pass values from list box to servlet

    hi
    did you resolve this issue? let me know the solution please...what code you got for resolving this?

    thanks
    K

  3. #3
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Re: hwo to pass values from list box to servlet

    Just an idea, I'm not sure if this works with servlets but this is how I've seen it in php ...

    Code:
    <select name='color[]' size=4 multiple>
    <option value='blue'>Blue</option>
    <option value='green'>Green</option>
    <option value='red'>Red</option>
    Notice the brackets in the name of the list: "color[]"
    Perhaps the same trick needs to be applied in Java.

    Never tried it before, but hey at least it's some inspiration for you, in case you're really stuck.
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width