我有一个产品类,它具有属性名称、描述和价格。
我打算在我的项目的应用范围内填充产品。我该如何实现这一目标?
其次,在填充产品后,我希望能够在 JSP 页面的表格中显示每个产品。每个产品都有自己的表格,列出其名称、描述和价格以及添加到购物车按钮
I have a class Products, which has the attributes name, description and price.
I intend to populate products in the application scope of my project. How do I go about achieving that?
Secondly, upon populating the products, I want to be able to display each product in a table in a JSP page. Each product will have its own table, listing its name,description and price and an add to cart button
发布评论
评论(1)
那么您想在 web 应用程序的生命周期内填充它一次吗?使用
ServletContextListener
。这样,产品将在每个 servlet
和每个 JSP 中
那么您想对产品进行分类吗?有一个
List
,然后Category
类有一个List
,或者使用Map Product>>
其中键是类别名称。至于如何显示它,已经在您的其他问题中得到了解答。
So you want to populate it once during webapp's lifetime? Use a
ServletContextListener
.This way the products will be available in every servlet by
and in every JSP by
So you want to categorize the products? Have a
List<Category>
then whereCategory
class has aList<Product>
, or use aMap<String, List<Product>>
where the key is the category name.As to how to display it, that's already been answered in your other question.