简体   繁体   中英

How to send html table data to the server (java/j2ee)

I am creating a web application using Java/J2ee on windows using Netbeans/Glassfish and sqlite as the Database.

I will be creating a table using jsp. The table has three columns and will have as many rows as the user wants.The user fills data in the cells and submits it . The data needs to be send to the server for processing. I see that servlets can read data from html forms through some methods, but I don't see a way to read the data from all the cells in a table. How do I do this ?

Also I need to implement paging using "previous" and "next" buttons so that the first page takes 20 rows(say) ,and so on , till the user finishes. I want to know if I should send the table data page by page to the server, or I can store the data temporarily in the client till the user finishes and send all the pages together to the server. I think it is not a good idea to burden the client ,if the user enters a huge number of rows.

This is my first web application, so please redirect me to any place which already explains these, in case one exists. I have done considerable search though.

Although you can use any of lots available web framework I'd recommend you to do something else. You said that it is your first web app, so it is expected to be relatively simple. So, you can stand without framework. Moreover you should learn the core, so you should stand without framework.

You can create JSP page that generates writable table. You should combine tags <table> and <input> . Each intput tag should have attribute name. All inputs in the same column will have the same name.

For example if your table contains 2 columns: car_model and car_manufacturer and 2 lines:

megane renault
323    mazda

the table will look like the following:

This table will be into form that will submit the stuff to servlet using HTTP POST. It is not a problem that you will get several parameters of the same name. Servlet API allows this: request.getParameters("car_manufacturer") returns array of strings that contain in our case renault and mazda.

Implementation of links previous and next is not very complicated. To get data you have to implement some paging anyway. So store index of first visible element in collection that you retrieve from DB and number of elements to show. Your JSP should take these elements, perform SQL query and show only relevant elements. Better solution is to modify query dynamically to retrieve only relevant elements.

I hope my answer helps. It does not contain exact todo list but I believe contains enough tips to start from. Good luck and have fun.

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