I am having a column named 'AREA' in a table named Editors. I am now making a html page for Staffs. In that page, i am having a field named 'AREA OF WORKING'. I have to retrieve values from AREA column of EDITORS table, and have to give the same areas to staffs in a combo box. So, that the staff can choose his area. So, i can't hardcode the values in HTML page.
So, how to proceed with the above mentioned problem?
Second, fetch the list of items and close all DB resources. Store the values in a List or Map for passing to the JSP. In the JSP use the JSTL and EL to create the select element. Under no circumstances should there be any Java code in the JSP.
Those weren't Bear's instructions. Bear said not to put Java code in a JSP.
Things I see that are wrong:
1) JDBC code in a JSP is incredibly hard to debug
2) The indentation is wrong making it hard to read the code
3) You have a connection leak - the connection needs to be closed in a finally block
4) You have no error handling.
And finally the error you are hitting. Picture the flow of what happens:
JSP 1 executes the Java code and stores a list in the request
JSP 1 renders the HTML
User clicks go - we now start a new request
JSP 2 looks in an empty session for a request attribute
In other words, the structure is fundamentally broken.