Issue
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);
}
Solution
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
Answered By - areus
Answer Checked By - Clifford M. (JavaFixing Volunteer)