• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to checkbox values in Servlet  RSS feed

 
Ramu Valivarthi
Ranch Hand
Posts: 37
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the JSP:
<form name="shop" action="servlet/sales" method="get">
<TABLE BORDER="1">
<TR><TH>select</TH><TH>Item</TH><TH>price</TH><TH>Quantity</TH></TR>
<TR><TD><input type="checkbox" name="which" value="shoes"></TD>
<TD>shoes</TD>
<TD> 1000</TD>
<TD><INPUT TYPE="TEXT" NAME="select"></TD>
</TR>
<TR>
<TD><input type="checkbox" name="which" value="shirt"></TD>
<TD>shirt</TD>
<TD> 2000</TD><TD>
<INPUT TYPE="TEXT" NAME="select1"></TD>
</TR>
<TR>
<TD><input type="checkbox" name="which" value="pant"></TD>
<TD>pant</TD>
<TD> 3000</TD>
<TD><INPUT TYPE="TEXT" NAME="select2"></TD>
</TR>

<TR>
<TD><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Submit"></TD>
</TR>

</TABLE>
</form>

Servlet:
ublic void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

HttpSession sess = request.getSession(true);
String no = (String)request.getParameter("select");
if(!no.equals("")){
try {
no1 = Integer.parseInt(no);
}catch (Exception e) {
System.out.println("ERROR :" + e.getMessage().toString());
}
}

String no2 =(String) request.getParameter("select1");
if(!no2.equals("")){
try {
no3 = Integer.parseInt(no2);
}catch (Exception e) {
System.out.println("ERROR :" + e.getMessage().toString());
}
}
String no4 = (String)request.getParameter("select2");
if(!no4.equals("")){
try {
no5 = Integer.parseInt(no4);
}catch (Exception e) {
System.out.println("ERROR :" + e.getMessage().toString());
}
}

String check[] = request.getParameterValues("which");
for(int i=0;i<=check.length;i++){
if(check[i].equals("shirt")){
String shirt=check[i];
int price = 2000 * no3;
sess.setAttribute("SESSOUT",String.valueOf(price));
sess.setAttribute("which",String.valueOf(shirt));
}else if(check[i].equals("shoes")){
String shoe=check[i];
int price = 2000 * no1;
sess.setAttribute("SESSOUT",String.valueOf(price));
sess.setAttribute("which",String.valueOf(shoe));
}else if(check[i].equals("pant")){
String pant=check[i];
int price = 2000 * no5;
sess.setAttribute("SESSOUT",String.valueOf(price));
sess.setAttribute("which",String.valueOf(pant));
}

ServletContext coxt = getServletContext();
RequestDispatcher rd = coxt.getRequestDispatcher("/index.jsp");
rd.forward(request,response);


}
}

If Iam selecting all the checkboxes at time Iam gettin error.Please help me
for this.Thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Iam selecting all the checkboxes at time Iam gettin error.
Would you care to share this error with us?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!