jquery, jsp, servlet
totalPrice
의 텍스트값을 가져오려고 한다.
<td><span id="totalPrice">0</span>원</td>
<input type="hidden" id="price" name="price">
...
<table class="orderSum">
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<tbody>
<tr>
<th>총 금액</th>
<td><span id="totalPrice">0</span>원</td>
</tr>
먼저 input 엘리먼트 price
를 hidden type으로 만든다.
const totalPrice = parseInt($('#totalPrice').text());
$('#price').val(totalPrice); // to pass the value to OrderServlet
return true;
totalPrice
의 text 값을 가져와서 price
의 value 값에 넣어준다.
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String price = req.getParameter("price");
...
}
요약: html에서 input 엘리먼트를 hidden type으로 하나 만들고 js파일에서 값을 넣어준다.