I am a beginner in Java and JSP. I have a JSP page that fetches data from a database and displays it in a table. I want to be able to display the details of each row when the user clicks on the row in the same JSP page. Can anyone help me with this?
Below is my JSP code:
<div class="release">
<table>
<% for (BuildStreamBean res : nm_release) { %>
<tr bgcolor=#ffffff>
<td id="release" style="cursor: pointer" onclick="getrelease(this, <%=res.getId_release()%>);">
<c:out value="<%=res.getNm_release()%>" />
</td>
</tr>
<% } %>
</table>
</div>
And here is my servlet code:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<BuildStreamDetailsBean> buildStreamDet = new ArrayList<BuildStreamDetailsBean>();
buildStreamDet = BuildStreamDAO.getBuildDetails(request.getParameter("id_release"), buildStreamDet);
List<BuildStreamDDBean> buildStreamTp = new ArrayList<BuildStreamDDBean>();
buildStreamTp = BuildStreamDAO.getBuildStreamTp(build_stream_tp);
request.setAttribute("build_stream_det", buildStreamDet);
request.setAttribute("build_stream_tp", buildStreamTp);
RequestDispatcher view = request.getRequestDispatcher("buildStream.jsp");
view.forward(request, response);
}
I have tried researching and it seems like I need to use an AJAX function, but I am not sure how to return the response to the JSP page from the servlet and display them in text boxes. Here I am fetching details of rows from the database.