Re: JSP Import CSV into database
Lew wrote:
Manish Pandit wrote:
Use struts. If not, write a servlet that accepts the request, override
the doPost() method, extract the file from the multipart request, and
process the records. Use the HttpServletResponse to write any messages
regarding error/success. You can use apache fileupload API to extract
the file from the request. Or if you want to do it
quick-and-not-so-dirty, post to another JSP that has the scriptlet java
code to process the request + write to the database.
Since you recommend Struts, instead of a monolithic servlet as the
alternative, how about a hand-constructed MVC app?
This is exactly why there are frameworks so you don't have to hand code
and reinvent the wheel every time.
FYI, Struts is old school by now, try Spring Framework, you only need 10
lines of code, a couple of spring config lines and the spring libraries
and you are ready to start processing the csv. The DB stuff can be done
by the Spring DB layer, which hides all JDBC mechanics, all you need
to do is to create a dao that provides the final sql statement and
spring will take of the rest.
tom