Search code examples
jspservletsjstljsp-tags

Why can't i pass map from jsp to Servlet


I want to pass a Map<String,Object> from jsp page to servlet. I have tried with c:set value="${map} scope="request"> and also with scriplet <%request.setAttribute("map",map)%> but when i try to retrieve map from servlet it always gives null ?


Solution

  • You are using submit button to trigger your servlet class. When you press submit button a new request object is created and it will not contain your map object.

    To resolve this problem you can use session object instead of request object.

    Note: Same request object transfer through jsp page to servlet class when you used forward method through them. Pay attention that in your case that is not possible in normal way; because you want to get some info from user and submit button will send them to servlet.