简体   繁体   中英

Checkbox status checked issue

I have a page that displays information of pizza (id, name, innards, price) view-pizza-item.jsp

I have servlet for view-pizza-item.jsp which is called: ViewPizzaServlet.java

I have editing page for the Pizza with tons of checkboxes for each innards material (meat, cheese, etc) edit-pizza-item.jsp

I have editing servlet for the editing page: EditPizzaServlet.java

My issue is that, i want to have the innards checkboxes in edit-pizza-item.jsp to be checked if the pizza has the said innards in view-pizza-items.jsp

Basically if the pizza has "Oregano" in earlier page, i want the "Oregano" checkbox to be checked in the editing page when i open it up.

Any idea how can i do this?

您必须在用户会话中设置对象bean'pizza',它将像这样在您的servlet之间共享:

httpRequest.getSession().setAttribute('pizza', pizza);

you know in advance that a certain type of pizza will have specific toppings, so when the user is willing to edit his/her margherita pizza you can simply load the object instance from the back-end just the way you do to show it in the view-pizza-item.jsp .

Now you have several options, but I would follow this approach: I'd leverage JavaScript to manipulate the Pizza model and AJAX to issue an HTTP call (POST or PUT) to persist changes for that specific Pizza instance.

Of course, you have to set up an endpoint able to serve such HTTP call. The endpoint could store the pizza modification which are ready to be displayed in a separate summary view. That's it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM