reset password
Author Message
lishenyu
Posts: 103
Posted 23:02 Oct 17, 2014 |

Dr Sun.

~After the item is checked out, the user should be redirected to the item log page , is this item log page the same one to the previous view item page? or can I do this ,after an item is checked out ,it goes to another page which can also show the item log ,with a return button more and no check out button ? this way I will need to create another servlet which is similar to "View" servlet but one button is different

 

cysun
Posts: 2935
Posted 08:35 Oct 18, 2014 |

Yes, the item log page is the view item page. There's no need to create another "View" servlet as your current View servlet should be able to tell whether an item is checked out and display the button(s) accordingly.

lishenyu
Posts: 103
Posted 09:03 Oct 18, 2014 |
cysun wrote:

Yes, the item log page is the view item page. There's no need to create another "View" servlet as your current View servlet should be able to tell whether an item is checked out and display the button(s) accordingly.

but now I got a problem , View item-->Check Out-->View Item , on the first  view item page and the check out page , I am able to get the id from previous page .But on the second View item page ,  I set the 'id' of check out page to the application scope ,but the second View item page failed to get the id which gives me an error "NumberFormatException:null"


 and on the second View item page ,the URL shows without  "?id=7" .


On the first View item page ,I did :


    Integer id = Integer.valueOf( request.getParameter( "id" ) );
    getServletContext().setAttribute( "iD", id );


On the check out page ,I did:


     Integer idd = (Integer) getServletContext().getAttribute("iD" );


     getServletContext().setAttribute( "id", idd );


Now ,from check out page go back to the first View item page ,the View item page should be able to use the "id' , but in fact it failed . also on the url without  "?id="


  Could you tell me why it's like this ? Thank you very much Dr. sun


    

cysun
Posts: 2935
Posted 12:55 Oct 18, 2014 |

You shouldn't store the id in application scope. Remember for a web application there could be multiple users using it at the same time (for large websites like Amazon the number of concurrent users could be in the millions). Imagine two users try to check out two different items and they both try to store the item id in application scope - one of the users' operation will get messed up.

In your case, all you need to do is to pass the item id as a request parameter when you do redirect, e.g. response.sendRedirect( "View?id=" + item.getId() ).

lishenyu
Posts: 103
Posted 13:32 Oct 18, 2014 |

Thank 有very much!

omizi
Posts: 22
Posted 02:14 Oct 22, 2014 |

thanks