Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda