I am new to java web programming. So, here what I have done,
I have built a decorator model and I have a servletthat invokes methods of different classes of the model.
In the JSP file I have a menu of items and quantity list for every item. The quantity is presented as a <List> </List>
What I need to do is that whenever the quantity is changed, call doPost which calls the decorate classes to recalculate the price and update the price in the same JPS page
I tried to use <select id="id1" name="id1" onchange="document.menu.submit()", the doPostis being called but I'm being forwarded to blank page!!! which is the servlet page. I want to update the price and stay in the same JSP page
So, basically I need to call servlet doPost or another function in servlet and return the price to the same JSP page
This is a snapshot of one item from JSP
<select id="id1" name="id1" onchange="document.menu.submit()">
<option value="0"> 0</option>
<option value="1"> 1</option>
<option value="2"> 2</option>
<option value="3"> 3</option>
<option value="4"> 4</option>
<option value="5"> 5</option>
</select>
<td> <input type="text" name="totalTxtbox" id="totalTxtbox" style="width:40px;"/> </td>
From servlet
private Model model;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
int id1=Integer.parseInt(request.getParameter("id1"));
double total;
total= calculatePrice(id1, id2, id3, id4, id4); // This method handles the price calculation
request.setAttribute("totalTxtbox", total);
}
Sorry if it is trivial problem!