I want to retrieve the name and quantity and price, these need to be made form fields ,so I want to put 'hidden' types like this in the
servlet.
<input type="hidden" name="price" value="4">
<input type="hidden" name="item" value="sock">
How do you code this in my servlet?
servlet part code....
public class MyBasket extends HttpServlet {
private
String startWebPage(){
return "<HTML><HEAD><TITLE>My Basket</TITLE></HEAD><BODY>" +
"<HTML><HEAD><TITLE>My Basket</TITLE></HEAD><BODY>" +
"<FORM action='checkout' method='POST'>" +
"<TABLE ALIGN='center' BORDER='1' WIDTH='50%' CELLSPACING='3' CELLPADDING='3'>" +
"<TR><TH ALIGN='center' VALIGN='top'>Item</TH>" +
"<TH ALIGN='center' VALIGN='top'>
Unit Price (�)</TH>" +
"<TH ALIGN='center' VALIGN='top'>Quantity</TH></TR>";
}
private String endWebPage(){
return "<TR><TD ALIGN='center' VALIGN='top' COLSPAN=3>" +
"<INPUT TYPE='submit' VALUE='Continue'>" +
"<INPUT TYPE='reset' VALUE='Clear'></TD></TR></TABLE></FORM></BODY></HTML>";
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
// Get the value of an initialization parameter
// Get the price parameter value
String parm = getServletConfig().getInitParameter("price");
int price = Integer.parseInt(parm);
String parm1 = getServletConfig().getInitParameter("price1");
int price1 = Integer.parseInt(parm1);
String parm2 =getServletConfig() .getInitParameter("price2");
int price2 = Integer.parseInt(parm2);
String parm3 = getServletConfig().getInitParameter("price3");
int price3 = Integer.parseInt(parm3);
String parm4 = getServletConfig().getInitParameter("price4");
int price4 = Integer.parseInt(parm4);
// Get the item parameter value
String item = getServletConfig().getInitParameter("item");
String item1 = getServletConfig().getInitParameter("item1");
String item2 = getServletConfig().getInitParameter("item2");
String item3 = getServletConfig().getInitParameter("item3");
String item4 = getServletConfig().getInitParameter("item4");
// TODO output your page here
out.println( this.startWebPage() );
out.println("<TR><TD>" + item + "</TD><TD>" + price + "</TD>");
out.println("<TD ALIGN='left' VALIGN='top'>" +
"<SELECT NAME='choices'>" +
"<OPTION>0" +
"<OPTION>1" +
"<OPTION>2" +
"<OPTION>3" +
"<OPTION>4" +
"</SELECT></TD></TR>");
out.println("<TR><TD>" + item1 + "</TD><TD>" + price1 + "</TD>");
out.println("<TD ALIGN='left' VALIGN='top'>" +
"<SELECT NAME='choices1'>" +
"<OPTION>0" +
"<OPTION>1" +
"<OPTION>2" +
"<OPTION>0" +
"<OPTION>0" +
"</SELECT></TD></TR>");
out.println("<TR><TD>" + item2 + "</TD><TD>" + price2 + "</TD>");
out.println("<TD ALIGN='left' VALIGN='top'>" +
"<SELECT NAME='choices2'>" +
"<OPTION>0" +
"<OPTION>1" +
"<OPTION>0" +
"<OPTION>0" +
"<OPTION>0" +
"</SELECT></TD></TR>");
out.println("<TR><TD>" + item3 + "</TD><TD>" + price3 + "</TD>");
out.println("<TD ALIGN='left' VALIGN='top'>" +
"<SELECT NAME='choices3'>" +
"<OPTION>0" +
"<OPTION>1" +
"<OPTION>2" +
"<OPTION>0" +
"<OPTION>0" +
"</SELECT></TD></TR>");
out.println("<TR><TD>" + item4 + "</TD><TD>" + price4 + "</TD>");
out.println("<TD ALIGN='left' VALIGN='top'>" +
"<SELECT NAME='choices4'>" +
"<OPTION>0" +
"<OPTION>1" +
"<OPTION>0" +
"<OPTION>0" +
"<OPTION>0" +
"</SELECT></TD></TR>");
out.println(endWebPage());
out.close();
}
/** Returns a short description of the servlet.
*/
public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}