Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!