Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating database record after displaying to user
    primarykey
    data
    text
    <p>I have a question on how to update a particular record in a database using JSTL and java servlets. </p> <p>Ok to call one record, I use a servlet to run a query to populate a jsp page using this type of format. </p> <pre><code> ResultSet results = getRecords.executeQuery(); //run database query Result result = ResultSupport.toResult(results); request.setAttribute("result", result); RequestDispatcher rd = request.getRequestDispatcher("/showReport.jsp"); //redirect to this page with query info rd.forward(request, response); </code></pre> <p>In the jsp page, I use this format to populate the page.<br> the row number is the corresponding to the index of the value on how the query is run.</p> <pre><code> &lt;c:forEach var="row" items="${result.rowsByIndex}"&gt; &lt;form action = "/runthis/servlet?id=${row[0]}" method = "get" &gt; Employee Name&lt;input type="text" value="&lt;c:out value="${row[2]}"/&gt;" /&gt; Department&lt;select&gt; &lt;option value="&lt;c:out value="${row[4]}"/&gt;"&gt;&lt;c:out value="${row[4]}"/&gt;&lt;/option&gt;&lt;/select&gt; &lt;input type="submit" value="Save"&gt; &lt;/form&gt; &lt;/c:forEach&gt; </code></pre> <p>So for instance, if someone changes the Employee Name, but leaves the Department field alone, or vice versa, how would I go about this? </p> <p>I think I should be able to kick this form action to a "update servlet", but I would rather not "update" every element in the record if I do not need to.</p> <p>Also I'm still learning web dev, so if you can think of a better way to prepopulate stuff, via javascript or whatever, I'm willing to try that as well, if it's a possible solution. </p> <p>Thanks for any help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload