| Author |
Displaying database info in JSP
|
Aniketh Narayanan
Greenhorn
Joined: Jan 05, 2013
Posts: 12
|
|
Hi,
I am working on a project where i am using jsp and servlets.
I am retrieving data from the database and displaying it in a table.
When i click on the respective ID, it should take me to a page where I can edit the fields.
This, is the code i have written..
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn= DriverManager.getConnection("jdbc dbc:resourcedetails1");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from resourcedetails");
while(rs.next()){
%>
<tr><td><a href="prjinsert.jsp"><%=rs.getString("EmployeeID")%></a></td><td><a href="prjinsert.jsp"><%=rs.getString("EmplyeeName")%></a></td><td><%=rs.getDate("DOJSyntel")%></td>
<td><%=rs.getDate("DOJRCIX")%></td><td><%=rs.getString("EmailID")%></td>
<td><%=rs.getString("DateofBirth")%></td></tr>
<%
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e){e.printStackTrace();}
%>
The place where i am stuck is, how do i send the ID clicked by the user to the servlet so that, that particular details can be retrieved in the appropriate fields in the next page ?
Please help.
Thankyou
|
 |
Vijay Vishwa
Greenhorn
Joined: Nov 21, 2010
Posts: 28
|
|
Hi Aniketh, please use the code tag on the tool bar for the code snippet which could help in reading
Am doing it for you now.
|
SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
|
 |
Vijay Vishwa
Greenhorn
Joined: Nov 21, 2010
Posts: 28
|
|
Regarding you question..
Have the table in the form
In prjinsert.jsp use
to get the selected EmployeeID.
Also try to use MVC architecture for designing the application. This will make your project more maintainable.
|
 |
Aniketh Narayanan
Greenhorn
Joined: Jan 05, 2013
Posts: 12
|
|
Thank you so much for your help.
But whenever i write the code...
<tr>
<td>
<a href="prjinsert.jsp?EID=<%=rs.getString("EmployeeID")%>"><%=rs.getString("EmployeeID")%></a>
</td>
</tr>
It does not retrieve any value from the database.
It gives me blank rows
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56153
|
|
You should not be writing Java code in a JSP. Java code should be in Java classes. The servlet controller should send the data to the JSP as a List or other not-a-result-set format.
Please read this article for how to properly structure web applications.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Vijay Vishwa
Greenhorn
Joined: Nov 21, 2010
Posts: 28
|
|
Print the value of
in the logs. See if any value is beeing passed.
also need to see the code to comments anything.
|
 |
Aniketh Narayanan
Greenhorn
Joined: Jan 05, 2013
Posts: 12
|
|
Here is the code.
For me to check the passing of the parameter, the link itself is not appearing.
And when i directly write
It retrieves the values properly.
|
 |
 |
|
|
subject: Displaying database info in JSP
|
|
|