0
我試圖從具有多行的表中選擇一行,並在另一個JSP中顯示所選行的值。從一個JSP中的表中獲取選定行的值到另一個JSP
但無論選擇哪一行,我只會得到第一行的值。從第一個JSP中選擇的表格數據從.js
文件填充。
下面是代碼從我第一次JSP代碼段:
<div>
<form class="form-inline" name = "select_req" action="/Main.do" method = post>
<table class="table" id = "searchresult">
<tr>
<th>From</th>
<th>To</th>
<th>Airline</th>
<th>Fare</th>
<th>Action</th>
</tr>
<tr ng-repeat="flight in flights | filter:query">
<td><input value = "{{flight.from}}" name = "from"></td>
<td><input value = "{{flight.to}}" name = "to"></td>
<td><input value = "{{flight.airline}}" name = "airline"></td>
<td><input value = "{{flight.fare}}" name = "fare"></td>
<td><input type="submit" value="Select" name = "select_req" class="btn btn-success"/></td>
</tr>
</table>
<input type="hidden"/>
</form>
</div>
這是它發送到另一個JSP,servlet代碼:
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String from = request.getParameter("from");
String to = request.getParameter("to");
String airline = request.getParameter("airline");
String fare = request.getParameter("fare");
HttpSession session = request.getSession();
session.setAttribute("from", from);
session.setAttribute("to", to);
session.setAttribute("airline", airline);
session.setAttribute("fare", fare);
request.getRequestDispatcher("/WEB-INF/views/Payment.jsp").forward(request, response);
}
最後的JSP是從選定的行表需要顯示:
<table class = "table">
<tr>
<th>From</th>
<th>To</th>
<th>Airline</th>
<th>Fare</th>
</tr>
<tr>
<td><%= session.getAttribute("from") %></td>
<td><%= session.getAttribute("to") %></td>
<td><%= session.getAttribute("airline") %></td>
<td>$<%= session.getAttribute("fare") %></td>
</tr>
</table>
我如何發送選定的行只使用JavaScript或將每個