简体   繁体   English

复选框状态已检查的问题

[英]Checkbox status checked issue

I have a page that displays information of pizza (id, name, innards, price) view-pizza-item.jsp 我有一个页面,显示比萨的信息(id,名称,内脏,价格) view-pizza-item.jsp

I have servlet for view-pizza-item.jsp which is called: ViewPizzaServlet.java 我有用于view-pizza-item.jsp的servlet,称为: ViewPizzaServlet.java

I have editing page for the Pizza with tons of checkboxes for each innards material (meat, cheese, etc) edit-pizza-item.jsp 我有一个比萨饼的编辑页面,其中包含每个内脏材料(肉,奶酪等)的大量复选框, edit-pizza-item.jsp

I have editing servlet for the editing page: EditPizzaServlet.java 我已经为编辑页面编辑了servlet: 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 我的问题是,我想检查一下edit-pizza-item.jsp中的innards复选框,如果披萨在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 . 您已经预先知道某种比萨饼将具有特定的浇头,因此,当用户愿意编辑他/她的玛格丽塔比萨饼时,您可以按照从后台加载对象实例的方式进行显示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. 现在您有几个选择,但是我将采用这种方法:我利用JavaScript来操纵Pizza模型,并利用AJAX发出HTTP调用(POST或PUT)以持久保存该特定Pizza实例的更改。

Of course, you have to set up an endpoint able to serve such HTTP call. 当然,您必须设置一个能够支持此类HTTP调用的端点。 The endpoint could store the pizza modification which are ready to be displayed in a separate summary view. 端点可以存储披萨修改,这些修改已准备好在单独的摘要视图中显示。 That's it. 而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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