Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As you're already changing the form action URL in the onclick (which is a very poor practice, but that aside), why not just adding the row identifier along as well?</p> <pre><code>&lt;input type="submit" name="&lt;%=t %&gt;" value="edit" onclick="this.form.action='df1.jsp?flag=1&amp;act=1&amp;edit=&lt;%=t%&gt;';this.form.submit();" /&gt; &lt;input type="submit" name="&lt;%=t %&gt;" value="delete" onclick="this.form.action='df1.jsp?flag=1&amp;act=1&amp;delete=&lt;%=t%&gt;';this.form.submit();" /&gt; </code></pre> <p>This way you can just do:</p> <pre><code>String edit = request.getParameter("edit"); if (edit != null) { // Edit button of row "edit" was invoked. Do your job here. } String delete = request.getParameter("delete"); if (delete != null) { // Delete button of row "delete" was invoked. Do your job here. } </code></pre> <p>Otherwise you'd need to prefix the button name with some fixed identifier:</p> <pre><code>&lt;input type="submit" name="edit_&lt;%=t %&gt;" value="edit" onclick="this.form.action='df1.jsp?flag=1&amp;act=1';this.form.submit();" /&gt; &lt;input type="submit" name="delete_&lt;%=t %&gt;" value="delete" onclick="this.form.action='df1.jsp?flag=1&amp;act=1';this.form.submit();" /&gt; </code></pre> <p>So that you can just do:</p> <pre><code>for (int t = 1; t &lt; 10; t++) { if (request.getParameter("edit_" + t) != null) { // Edit button on index "t" was invoked. Do your job here. break; } if (request.getParameter("delete_" + t) != null) { // Delete button on index "t" was invoked. Do your job here. break; } } </code></pre> <hr> <p><strong>Unrelated</strong> to the concrete problem, writing JSPs this way with <em>scriptlets</em> <code>&lt;% %&gt;</code> is since a decade considered oldschool and a poor practice. See also <a href="https://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202">How to avoid Java code in JSP files?</a></p>
 

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