• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

how to populate textboxes with values from database based on id  RSS feed

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp file (show.jsp) that displays all values from a database in a table. I added a column in this table so an edit link appears next to each of these values, and when I click that link an edit.jsp page opens with textboxes that I want to populate with the values of the item I selected in the first jsp. I then want to update these values and save to the database. So the textboxes in edit.jsp should populate with the values I selected from the table in show.jsp
My problem is I don't know how to populate the textboxes in edit.jsp from the item I selected in show.jsp

here's the edit.jsp that's just the form for displaying the information:


and here's the servlet the handles the code:
 
Sheriff
Posts: 67257
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Karen Wilson wrote:My problem is I don't know how to populate the textboxes in edit.jsp from the item I selected in show.jsp



The way that you populate input elements is via their value attribute. So what you want to end up with is HTML like: <input type="text" name="city" value="Boston">

So in the page controller you need to put the values into request scope so that they can be accessed in the JSP via the EL. So your markup could look something like:
 
Bear Bibeault
Sheriff
Posts: 67257
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. If it's possible that the city name can contain the double-quote character, you'd need to escape the value with <c:out>
 
Karen Wilson
Ranch Hand
Posts: 70
 
Bear Bibeault
Sheriff
Posts: 67257
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no way of knowing. Obviously your server code that processing the submission from show.jsp has the values. It's not up the JSP to make any decisions, but for the controller code to send the appropriate data to the JSP.
 
Karen Wilson
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so how do i get the jsp to send the data to the servlet?
I need to get the id of the property i selected and pass that id to the edit.jsp page right?
then the edit.jsp will display all the information
 
Bear Bibeault
Sheriff
Posts: 67257
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Communication from the client to the server take place via a form submission or a hyperlink. In either case, data is carried to the server via request parameters; either from elements int he form, or the query string of the link.

Technically, a JSP does not communicate with a servlet. The JSP is transformed into an HTML page which is loaded into the browser. It is the HTML (not the JSP) that in turn submits a form or processes a link.
Is that the communication you are asking about?
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet code you show is what happens after the user clicks the "SAVE" button from the edit screen. What you are missing is the servlet code that is run after the user clicks the hyperlink from the "show" page. This is the code where you should be loading the object based on ID, and then setting the request object with all the various parameters you want to populate your form with. Then as BearB mentioned, you will do something like value="${MyVar}" for each element where your retrieving the data from the request object you set in your servlet.
 
Forget Steve. Look at this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!