Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

220
Vistas
how to access this array on a servlet?
function getboxvalues(){
var array = [];
$("input:checkbox[name=delbox]:checked").each(function() {
                array.push($(this).val());
            });
            
JSON.stringify(array);
console.log(array);

   $.ajax({
    url: 'Deletestudent',
    dataType: 'json',
    data: {
        object: {"delbox":array}
    },
    type: 'GET'
    });
}    

Edit : this is the servlet Code i might have to parse the object im getting but as i was trying to get it to work , most people were just suggesting accessing it through the ususal way .

public class Deletestudent extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Deletestudent() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String[] idlistString = request.getParameterValues("delbox");
        
        
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(request.getParameter("delbox"));
        doGet(request, response);
    }

}

i tried accessing it through request.getparameter , but it returns as null eventho i tried logging it in the JS file and it comes out as a normal array.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You have two problems:

  1. You have forgotten about object entirely even though you explicitly put it in your data
  2. jQuery follows the PHP-ism of renaming parameters with array values so they have [] appended to them and you didn't account for that.

Your URL is going to look something like:

/Deletestudent?object%5Bdelbox%5D%5B%5D=foo&object%5Bdelbox%5D%5B%5D=bar

So you need to ask something with the right name.

request.getParameter("object[delbox][]"));
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to use POST method as you are trying to send a JSON data. Then you will get as request.getparameter as String, but again you may need to make that to JSON to use it easily.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda