Reputation: 127
<table border="1" cellpadding="5" id="newtable">
<!-- <caption id="tablehead">Rooms are available!</caption> -->
<!-- <tr class="hover"> -->
<tr>
<th>Room No</th>
<th>AC</th>
<th>Deluxe</th>
<th>Tariff</th>
</tr>
<c:forEach var="room" items="${myrooms}">
<tr bgcolor="#4B476F" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#4B476F';">
<td class="nr">1</td>
<td name="ac"><c:out value="${room.ac}" /></td>
<td name="deluxe"><c:out value="${room.deluxe}" /></td>
<td>₹<c:out value="${room.price}" /></td>
<td><button type="button" class="mybutton" onclick="location.href='passtopayment'">Pay</button> </td>
</tr>
</c:forEach>
</table>
I want to get the td value for AC and Deluxe column on click of the corresponding row. However, when the execute the following servlet code I get, null null is printed. Please help!
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String ac = request.getParameter("ac");
String deluxe = request.getParameter("deluxe");
out.println(ac);
out.println(deluxe);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
Upvotes: 0
Views: 619
Reputation: 46871
You are using location.href='passtopayment'
that is not the correct way to submit a form.
It's just a like a separate request to the Servlet nothing will be send to the Servlet.
You should use form
and submit the request to the Servlet.
<form action="passtopayment" method="post">
<!-- HTML controls -->
<input type="submit" value="Submit"/>
</form>
Here is detailed Example
Upvotes: 3