0

This is the code I have:

    <table border="2">
<tr>
<th>CourseID</th>
<th>SectionNo</th>
<th>Add Info</th>
</tr>
    <% while(rs.next()){    %>  

        <tr>
            <FORM NAME="actionForm" action="ProfCourseUpdate" method='post'>
            <td> <%=rs.getString("CourseID") %> </td>
            <td> <%=rs.getInt("SectionNo") %> </td>
            <td> <input type="submit" name="ProfCourseUpdate" value="Update Course Info"></td>
            </FORM>
        </tr>

    <% } %>
</table>

I'm pulling information from a database and putting them into their respective columns in a table. So it looks like: |Course --- Section --- (Button)|

When I have a user click the submit button I want to be able to pass along the data from the entire row. I've tried hidden input in this way:

<td> <%=rs.getString("CourseID") %> </td><td><input type="hidden" name="Course" value="<%rs.getString("CourseID") %>"></td>

It just results in some strange table formatting and didn't work.

geoxile
  • 348
  • 1
  • 6
  • 16

1 Answers1

1

You need to put all the information you want to pass on INPUT (text, hidden) or using a URL to inform that to a servlet.

First, a couple of things you might want to consider:

  1. Use only one form tag in your page instead of using one for each row.
  2. Enclose the whole table within your form tag.

You will end up with something like this:

<FORM NAME="actionForm" action="ProfCourseUpdate" method='post'>
<table border="2">
<tr>
    <th>CourseID</th>
    <th>SectionNo</th>
    <th>Add Info</th>
</tr>
<% while(rs.next()){    %>  
<tr>
    <td> <%=rs.getString("CourseID") %> </td>
    <td> <%=rs.getInt("SectionNo") %> </td>
    <td> <input type="submit" name="ProfCourseUpdate" value="Update Course Info"></td>
</tr>
<% } %>
</table>
</FORM>

Now, with that all cleared out of the way, you might want to use a different approach. If you want your table for selecting a course/section purpose, you don't even need a form (or a submit button for that matter).

You could replace this:

    <td><input type="submit" name="ProfCourseUpdate" value="Update Course Info"></td>

With this:

    <td><a href="/ProfCourseUpdate?CourseID=<%=rs.getString("CourseID") %>&SectionNo=<%=rs.getInt("SectionNo") %>">Update</a></td>

This way, your ProfCourseUpdate servlet with receive the two variables needed (CourseID and SectionNo) to retrieve and update that row.

If you must use a button, you could use the same technique, but encoding CourseID and SectionNo on value. But I would not recommend it.

Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
  • Yes, I tried using hidden input, but it didn't work. How can I create a URL containing unique information for each row? – geoxile Aug 11 '14 at 01:58
  • Hi geoxile. Looks like you don't have much experience on WEB DEVELOPMENT. Before digging into SERVLET stuff, I would recommend reading about GET and POST methods on a HTML FORM. How do the work, how do they pass information to the server. It will give you a cleaner scenario to start developing software with Servlets and JavaEE technology. – Pablo Santa Cruz Aug 11 '14 at 02:06
  • Hi. Yes, I'm not very experienced. I have tried reading tutorials on JSP but my retention from reading is pretty poor, especially since I find reading dreadful at times, so I find actually working on a project and getting stuck on things is the best way for me to learn. Thanks for all your help. – geoxile Aug 11 '14 at 02:10