0

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 ?

7
  • is it the same request when you go from JSP to servlet?
    – dReAmEr
    Jan 6, 2015 at 16:52
  • How do you do that? How do you call your servlet from jsp page? Jan 6, 2015 at 16:56
  • but you have set this map to request scope,and if it's a new request,map won't be available in second request,just for testing set it at some other scope,like session or context.
    – dReAmEr
    Jan 6, 2015 at 16:57
  • 1
    @Outofmemory: Right, But what is not possible? I just want to know, how does he go through jsp page to servlet class, by submit button, by dispatcher, or anything else. Jan 6, 2015 at 17:03
  • @AliSepehri.Kh I am navigating from jsp to servlet via submit button
    – harpal18
    Jan 6, 2015 at 17:05

1 Answer 1

1

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.

7
  • is there any alternative , i dont want to use session object?
    – harpal18
    Jan 6, 2015 at 17:12
  • Usaually there is no need to do this, sending an object to client and get same object from client. You are doing something wrong. Jan 6, 2015 at 17:19
  • thanks for helping me out . Is there any way ? i am not modifing anything in map , i just want to bypass it
    – harpal18
    Jan 6, 2015 at 17:20
  • @hpppy18: 1) Retrieve this Map object in your second servlet (maybe you are doing it again) 2) Use session object (same object for each user). The ways I know. Jan 6, 2015 at 17:25
  • ..is this a good idea ..lets say user had done some shopping and added some items in shop cart and did submit ,from servlet side i will to pass the same shopped item object to client , and then what if client wants to add more items in it ...my whole point is setting data in session scope will get refelected for all users right , please correct me if my concept it wrong
    – harpal18
    Jan 6, 2015 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.