JavaEE model1 model realizes commodity browsing records (removing duplicate browsing records) (I)

In JavaEE, the model1 model is centered on the JSP page. The JSP should not only logically process the browser's request (using JavaBeans), but also display the relevant pages when accessing the database. In the model1 model, there is no servlet. The result of model1 is as follows:

The maintainability and extensibility of model 1 are poor, which is only suitable for small projects.

Run the results first

goods. jsp

A picture representing a product in the code

Click the picture of the product to transfer the ID value of the current product to the details page The JSP displays the detailed product by the product ID, and the browsing record is maintained by cookies

Dao layer is responsible for the query operation of commodities in the database

Entity class items of goods

The hascode and equals methods are rewritten here to modify the comparison method (all items are new objects, even if the contents of the two commodities are the same, they will not be equal. Therefore, the comparison method should be modified) because we can't refresh the current commodity browsing record for browsing records. We just need to ensure that there is only one commodity in the browsing record, so the gethistoryview method in the Dao layer has this sentence code

Then the tool class dbhelper singleton pattern obtains the connection object

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>