while submitting this page u store ur check box value in attribute , that attribute u need to store in session and when u return back to page B , u retrive that value from session and set through javascript as selected..(SINGH IS KING):)

If Servlet A is doing the POST to Servlet B then it's not a checkbox, and it's simply a parameter. "checkbox" only has meaning on the browser. By the time you get to the servlet it is simply another parameter.

Step us through the flow, from the browser submitting the form containing the checkbox.
That is, Submit -> Servlet A -> forward or redirect to Servlet B -> etc etc.

Can I suggest you remove the html from the servlets?
Forward to an html page or a JSP rather than have the servlet output the html...that's not the servlets job, and it'll make the flow a lot clearer.

Right, whether you've done that or not you need to get the value of "checkbox" from the session and use that to decide whether the checkbox (html) attribute "checked" needs adding. But I would really split it out to a JSP first.

Now, what you want is to check if there is a "checkbox" attribute in the session. Presumably you have them numbered (ie "checkbox1" etc)? If that exists then you want to add "checked" in the output string.

it makes no sense but the issue is with using the submit button. Forwarding works without pressing the back button but it doesnt work when i use the back button .. [what can go wrong in putting the forward code inside an IF stmt]

Now i can pass the session value but the problem is that once if i have selected the checkbox it always remains checked regardless of whether i unchecked or not.

i.e. suppose if i select the checkbox in 1st visit then come back to JSP by pressing back from servlet [showin check box as check here] and Deselect/Unchecked the checkbox and go to servlet page [where the data is null as it was uncheck] and press back again but this time also the checkbox is also showing as checked which shouldnt be as i have unchecked it.

just in short the session value is not changing with selecting / deselecting the checkbox.

what may be the reason?? i have included the code below. its just a small code for testing.

So, in the servlet, it will set the "book1" value in the session. and display the HTML you have (since you already have a JSP I would really recommend creating another one for this stuff).

Then you click the "back" button of that page, which takes you back to the original JSP, with the checkbox checked. You uncheck the checkbox and hit "enter". Return to the servlet, and then again hit "back".

Now...where in that flow do you remove the "back1" attribute in the session?

I have tried using session.removeAtrribute("book1") inside the else stmt of servlets as shown below but in that case the value is not return back to the JSP and if i dont put the removeAtrribute() then the value remains always checked if once checked.

I have also converted both the code in servlets and its working find there. I just dont know why its not working with the servlets and JSP

You have a starting JSP consisting of the "order" page, with the checkbox.
This goes to the ShowItem servlet on Enter.
That servlet should then display the item selected (presumably)...well, to be honest it should forward to the JSP that displays the item. Normally it would get the data from a db, store it in the request and then forward, so mimic that in the servlet.

That "display" JSP has two buttons, Buy and Back. Each of those does something different, so I would have two more sevlets. Currently, of course, it doesn't look like they do different things, but no harm splitting them out now.

Back will, therefore, get the value from the session and store it in the request (if it exists), removing the attribute in the session. The original "order" JSP will look in the request for the state of the checkbox.