0

I'm refreshing my servlet knowledge by creating a simple api after many days. While trying to supply array parameters in query for get request, I'm getting java.lang.IllegalArgumentException: Invalid character found error. I tried the same thing with spring framework before & was working perfectly. So, whats problem with servlet code.

Here is the request: http://localhost:8080/HelloServlet/welcome?name[]=akshay,barpute.

Below is the servlet code for your reference.

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws 
    ServletException, IOException {
    // TODO Auto-generated method stub


    Map<String, String[]> data = request.getParameterMap();
    this.s = data.get("name")[0];
    response.getWriter().append("Hello ").append(s);
}

1 Answers1

0

Don't know about that spring feature, but the correct way to do this with a servlet is to repeat the name parameter:

http://localhost:8080/HelloServlet/welcome?name=akshay&name=barpute
areus
  • 2,880
  • 2
  • 7
  • 17