Good day!
How can I access the HTML text field value inside a servlet? My example code is as follows:
out.println("<html><head></head>");
out.println("<body>");
out.println("Item not found...");
out.println("<h2>Add Item:</h2>");
out.println("<form action = \"AddandSearch\">");
out.println("Item Name: <input type =\"text\" name =\"name\"> <br>");
out.println("Unit Price: <input type =\"text\" name =\"unitPrice\"> <br>");
out.println("On Stock : <input type =\"text\" name =\"stock\"> <br><br>");
out.println("<input type =\"submit\" value =\"Add Item\">");
out.println("</form>");
out.println("</body>");
out.println("</html>");
I need to get the value of name, unit price and stock after the user presses the button so i can put it in an arraylist. Is it possible to assign it on the same servlet? I tried using this code:
String id = request.getParameter("name");
but it is not working because the button must be pressed first. Can i use a getter and setter method or anything equivalent? I need a textfield for the data entry and it must be done inside a servlet. The result must also be generated inside the same servlet. Thank you.