• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Editing mySQL data that is displayed in a html table

 
Greenhorn
Posts: 6
Netbeans IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Maire Marnane
Greenhorn
Posts: 6
Netbeans IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that.
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Maire Marnane
Greenhorn
Posts: 6
Netbeans IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic