简体   繁体   中英

How to display values from database in jsp page using java class??

I have a database with tables and values. I want to fetch that data and display it in jsp page. Don't want to write query in jsp page, separate java class, creating object values and then displaying it in html, Can anyone help me with proper structure of code.

Thanks

Look up servlet. When you submit a page, you can use servlet to access the database and store the result in your request object. You can then use that request object in your jsp page to display the result.

This is a very simple approach. You may want to consider Struts MVC pattern, if you want to do it the right way.

The right way to do that is creating a DAO and use it for all the in/outs from the DB. The controller explained by javaStudent, instanciate a DAO class and store the data in a Java Bean. Here you have good information about all that and about the correct way to program web aplication based on MVC:

http://pdf.coreservlets.com/

I wish it could help!

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