In the below servlet there are three buttons "Submit" whose
type=submit,"Reset"whose type=reset,"Add" whose type=button.when the user
clicks on "Add" button this button invokes a java-script function which
takes the values from the form elements and stores in seperate arrays.I'm
using java-script for this and storing them in (javascript)arrays.i used
this to avoid refreshing the screen for each new set of values. Now after
he finishes entering all the values he clicks "Submit" which has to take all
the values from the arrays and store them in the database.now how do i
retrive these values in the doPost method of the same servlet.Please send me
ur reply as soon as possible.
********************* servlet code****************
public class AddMetric extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws
ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
getServletContext().getRequestDispatcher("/servlet/OperatorHeader").include(req,res);
out.println("<script language=\"java-script\"
src=\"../validation.js\"></script>");
out.println(" <script>");
out.println(" <!--");
out.println(" arr1 = new Array(4);");
out.println(" arr2 = new Array(4);");
out.println(" arr3 = new Array(4);");
out.println(" arr4 = new Array(4);");
out.println(" arr5 = new Array(4);");
out.println(" i=0;");
out.println(" function addmetric() {");
out.println(" if(i>4) {");
out.println(" alert('Sorry now you can add 5 items at a time \n Please
Submit then you can again');");
out.println(" return false; ");
out.println(" }");
out.println(" arr1[i]=form.metricName.value;");
out.println(" arr2[i]=form.metricDatatype.value;");
out.println(" arr3[i]=form.unit.value;");
out.println(" arr4[i]=form.startValue.value;");
out.println(" arr5[i]=form.endValue.value;");
out.println(" i=i+1;");
out.println(" }");
out.println(" -->");
out.println(" </script>");
out.println("<td width=\"596\" height=\"215\"> <p
align=\"center\"><strong><small><font face=\"Tahoma\">Add a");
out.println(" new Metrics<small><br>");
out.println(" </small></font></small></strong></p>");
out.println(" <form name=\"form\" method=\"post\"
action=\"AddMetric\">");
out.println(" <div align=\"center\"><center><table border=\"0\"
cellspacing=\"0\" width=\"355\" height=\"182\"");
out.println(" cellpadding=\"0\">");
out.println(" <tr>");
out.println(" <td width=\"216\" height=\"38\"
colspan=\"2\"><small><font face=\"Tahoma\"><strong>Metrics
Name</strong></font></small></td>");
out.println(" <td width=\"179\" height=\"38\"
colspan=\"2\"><small><font face=\"Tahoma\"><input type=\"text\"");
out.println(" name=\"metricsName\"
size=\"18\"></font></small></td>");
out.println(" </tr>");
out.println(" <tr>");
out.println(" <td width=\"216\" height=\"41\"
colspan=\"2\"><small><font face=\"Tahoma\"><strong>Metrics");
out.println(" Data Type</strong></font></small></td>");
out.println(" <td width=\"179\" height=\"41\"
colspan=\"2\"><small><font face=\"Tahoma\"><input type=\"text\"");
out.println(" name=\"metricsDatatype\" size=\"18\"
onfiltered=\"val(MetricsName)\"></font></small></td>");
out.println(" </tr>");
out.println(" <tr>");
out.println(" <td width=\"216\" height=\"36\"
colspan=\"2\"><small><font face=\"Tahoma\"><strong>Unit of");
out.println(" Measurement </strong></font></small></td>");
out.println(" <td width=\"179\" height=\"36\"
colspan=\"2\"><small><font face=\"Tahoma\"><select
name=\"unitOfMeasurement\"");
out.println(" size=\"1\">");
out.println(" <option value=\"Inch\">Inch</option>");
out.println(" <option value=\"Cm\">Cm</option>");
out.println(" <option value=\"Feet\">Feet</option>");
out.println(" <option value=\"Meter\">Meter</option>");
out.println(" </select></font></small></td>");
out.println(" </tr>");
out.println(" <tr>");
out.println(" <td width=\"216\" height=\"31\"
colspan=\"2\"><small><font face=\"Tahoma\"><strong>Start
Value</strong></font></small></td>");
out.println(" <td width=\"179\" height=\"31\"
colspan=\"2\"><small><font face=\"Tahoma\"><input type=\"text\"");
out.println(" name=\"startValue\" size=\"18\"
onfiltered=\"val(MetricsDataType)\"></font></small></td>");
out.println(" </tr>");
out.println(" <tr>");
out.println(" <td width=\"216\" height=\"36\"
colspan=\"2\"><small><font face=\"Tahoma\"><strong>End
Value</strong></font></small></td>");
out.println(" <td width=\"179\" height=\"36\"
colspan=\"2\"><small><font face=\"Tahoma\"><input type=\"text\"");
out.println(" name=\"endValue\" size=\"18\"
onfiltered=\"val(StartValue)\"></font></small></td>");
out.println(" </tr>");
out.println(" <tr>");
out.println(" <td valign=\"middle\" align=\"center\"
width=\"132\"><small><font face=\"Tahoma\"><input");
out.println(" type=\"submit\" value=\"Submit\"
name=\"submit\"></font></small></td>");
out.println(" <td valign=\"middle\" align=\"center\"
width=\"126\" colspan=\"2\"><small><font face=\"Tahoma\"><input");
out.println(" type=\"reset\" value=\"Reset\"
name=\"reset\"></font></small></td>");
out.println(" <td valign=\"middle\" align=\"center\"
width=\"120\"><font face=\"Tahoma\"><input type=\"button\"");
out.println(" value=\"Add\" name=\"add\"
onfiltered=\"addmetric()\"></font></td>");
out.println(" </tr>");
out.println(" </table>");
out.println(" </center></div>");
out.println(" </form>");
out.println(" </td> ");
getServletContext().getRequestDispatcher("/servlet/CopyRightTemplate").include(req,res);
out.close();
}
}
*****************************************************
_______________________________________________________
Get 100% FREE Internet Access powered by Excite
Visit http://freelane.excite.com/freeisp
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html