Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to populate the result obtained from a list into a form's field

bhavana chadaga
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was doing this very simple web application using servlets,jsp and mysql DB. But feeling a little stuck now.

The application takes user input from a form 'index.jsp' and uses servlet to store it into the DB. The same 'index.jsp' has a search button with an empty text box that takes in the value of employee id to search employee.
But this is inside another form which submits to another servlet called ''. I am supposed to pass this result data to another jsp page and fill the fields in that jsp page with these values.

I am halfway through...I have created an arraylist and added the obtained employee data into it and passing it to another jsp called 'display.jsp' but there in that jsp i do not know how to fill it into the form fields.
The display.jsp is the same as index.jsp with same fields.
I want the display.jsp to look like a prefilled form. How do i do it?

This is my

This is my index.jsp

This is my display.jsp for now where i have juste fetched the list values and displaying...
But i want it to look like index.jsp but populated with the fetched data..
How do i do it?

Bear Bibeault
Author and ninkuma
Posts: 65273
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Three things come to mind:
  • You are using scriptlets (Java code) in the JSP. This has been obsolete for over 15 years. 15 years! You should be using the JSLT and EL in the JSP. Please update your JSP knowledge with modern concepts.
  • Never pass a result set to a JSP. In fact, a result set should be closed as soon as possible. Get the data from the result set, store it normal Java collections and beans, and then pass that along.
  • In order to pre-populate the value of form fields, set the value into the element's value attribute.
    Dave Tolls
    Ranch Hand
    Posts: 1967
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It's not a ResultSet (even if that's its name).
    It's a List<String>.

    So my first comment would be, that should be an object of a class representing that data, rather than a List.

    Second would be, you are not closing your statement/resultset etc.  This will cause a resource leak in your database.

    Third, you should list the column names in your SELECT.
    So, instead of
    SELECT * ...
    you would use
    SELECT id, name, some_number, some_other_data ...

    In your case this is doubly important in that you use columnIndex to reference the columns in the result set, and there is no guarantee of order of the columns that come back from a SELECT *.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic