hi
can any one please help me how to retieve dynamically loaded data in a html radio button in to jsp page..
actually i tried to load user account no from database in to radio buttonin html..this worked perfect .. but upon clicking the submit button i want to get the details of the person with that account no from the database and i have to delete the same from the database if needed..

Dani AI

Generated

was on the right track: render each account as a radio whose value is the account identifier, submit the form, then query the database for that id on the server. Below is a concise, practical pattern that avoids scriptlets, uses a controller for processing, and shows safe DB access and delete handling.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<form method="post" action="accountAction">
  <c:forEach var="acct" items="${accounts}">
    <label>
      <input type="radio" name="accountId" value="${acct.id}" />
      ${acct.accountNo} - ${acct.holderName}
    </label>
  </c:forEach>

  <button type="submit" name="op" value="view">View</button>
  <button type="submit" name="op" value="delete">Delete</button>
</form>

On the server side, read request.getParameter("accountId"), validate it, then use a PreparedStatement to fetch or delete. Example flow inside a servlet/DAO:

String idStr = request.getParameter("accountId");
if (idStr == null) { /* handle: no selection */ }
int id = Integer.parseInt(idStr);

if ("view".equals(request.getParameter("op"))) {
  // dao.findById(id) -> forward to details JSP
} else if ("delete".equals(request.getParameter("op"))) {
  // dao.deleteById(id) inside a transaction
  // then response.sendRedirect("accountList");  // PRG to avoid double-submit
}

Practical tips and cautions: always use PreparedStatement to prevent SQL injection; require POST for deletes and perform permission checks and audit logging (or soft delete) before removing accounts; after delete redirect (POST-Redirect-GET) to avoid resubmission; if radios are inserted via JavaScript/AJAX ensure they exist inside the <form> with correct name and value so the browser submits them; check for null parameters and handle parsing errors. This approach keeps UI rendering, DB access and control flow clean and robust for both view and delete operations.

Recommended Answers

All 2 Replies

When you submit to the next page read the value of the radio button and query the database based on that number. Then display the data from the DB.

What code did you use to display the radio buttons. I assume that the value of the radio buttons are the number(id) of the account.

<input type="radio" name="radioAccountNo" value="<%=accountNum%>" />

And the above is in a for loop with the name being the same and you change only the value.

thanks friend
....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.