aspose file tools*
The moose likes JSP and the fly likes Editing mySQL data that is displayed in a html table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Editing mySQL data that is displayed in a html table" Watch "Editing mySQL data that is displayed in a html table" New topic
Author

Editing mySQL data that is displayed in a html table

Maire Marnane
Greenhorn

Joined: Nov 27, 2012
Posts: 6

I am very new to this. I'm doing a course and need some help please. I'm new to coderanch too, so if I'm doing things wrong please tell me.

I've got a jsp that displays the contents of a mySQL database table. I have to add an edit button to the beginning of each record, which will open a new jsp that will allow edit / delete/ update to the database.

I've managed to get the data to display, and I've added the edit button (not sure if it's the best way but it does open the next jsp). What do I use on the next jsp to allow me to edit the data.

Weclome.jsp - I have a <jsp:usebean> for categoriesBeanData






TestServlet takes the hidden fields from the form, connects to the database and gets a resultset of one row.
It then does request.setAttribute for each column and does a forward to EditCategories.jsp

How do I display the data in EditCategories.jsp so that it can be editied? If I put it in a html table it not editable..

EditCategories.jsp



Any suggestions would be really welcome, as I feel like I'm not getting anywhere with this...
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

The EditCategories.jsp submits the updated values in the ean to a servlet which in turn updates them to the database.
Moreover, things like this can be done on the same JSP (Weclome.jsp in your case) through use of AJAX in order to permit further working on the same page.

SCJP, SCWCD.
|Asking Good Questions|
Maire Marnane
Greenhorn

Joined: Nov 27, 2012
Posts: 6

Thanks for that.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1001
    
  13

The only editable field you can use is an input field of type text (ignoring textarea for now). You can put an input field inside your td elements, but you should keep in mind that the use of tables like this is frowned upon. Using CSS is the correct way to layout your input fields and labels. Tables should be used only for tabular data like your first page.

The input fields will be part of a form so that when you've finished editing you can click the submit button and the new values will be posted to a servlet and after that you update the database.

One more point. I see that you are using a mix of scriptlets (the stuff between the <% %>) and JSTL (the c:forEach stuff). Learning scriptlets is a necessary evil because you will likely have to support existing code someday that was written like this. But you should be aware that it's a widely discredited practice that should never be used for new development.

And welcome to the Ranch!


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Maire Marnane
Greenhorn

Joined: Nov 27, 2012
Posts: 6

Hi JK.

You said:
One more point. I see that you are using a mix of scriptlets (the stuff between the <% %>) and JSTL (the c:forEach stuff). Learning scriptlets is a necessary evil because you will likely have to support existing code someday that was written like this. But you should be aware that it's a widely discredited practice that should never be used for new development.


Just to be 100% clear then, I shouldn't use <% %>, use JSTL instead?

And
The only editable field you can use is an input field of type text (ignoring textarea for now). You can put an input field inside your td elements, but you should keep in mind that the use of tables like this is frowned upon. Using CSS is the correct way to layout your input fields and labels. Tables should be used only for tabular data like your first page.

The input fields will be part of a form so that when you've finished editing you can click the submit button and the new values will be posted to a servlet and after that you update the database.


I had a suspicion that this was not best practice, but it's the way I've been asked to do the assignment. I think it will be re-written in a later assignment. Thanks a million.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1001
    
  13

Maire Marnane wrote:
Just to be 100% clear then, I shouldn't use <% %>, use JSTL instead?


Correct. Check out this faq as a good start and you might want to read some of the others while you're there.

Maire Marnane wrote:
I had a suspicion that this was not best practice, but it's the way I've been asked to do the assignment. I think it will be re-written in a later assignment. Thanks a million.


Of course when applied to school work, always do it the way the instructor has specified. But any decent course will eventually make sure you understand the difference between supporting 10 year old code of scriptlets, and writing new code with JSTL and EL.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Editing mySQL data that is displayed in a html table