I'm sending a POST request using jQuery:
$.post(
'test',
{ foo: 'bar'}
);
And I have a simple servlet for processing it:
@WebServlet("/test")
public class TestServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Map<String, String[]> parameterMap = req.getParameterMap();
}
}
But the requestMap in the servlet turns out to be empty. What am I doing wrong?
Edit: Forgot to mention that I call this script from the JSF Facelet page. Don't ask me why I bother manually issuing Ajax requests, and why I use servlets to process them. It's a long story. I know it's not a JSF'ish way.
After @BalusC answer, I tried adding a servlet filter like this:
@WebFilter(urlPatterns="/test")
public class TestFilter implements Filter {
@Override
public void destroy() { }
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
Map<String, String[]> parameterMap = request.getParameterMap();
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException { }
}
And it worked! Not only I was able to get the parameters in the filter, but also they were accessible in the servlet! So, can somebody explain me what sort of magic is this?