Question: how can we  built date validation servlet? i need help in jsp and servlet .i have  one jsp page in that page i have problem in servlet and jsp page .\ni have one jsp page in the that page i have "date ,Ph,metrerial etc r fields ... so, when i enter  any date then its releted record will be fill up .\nDATE: 11/2/2003   \nfe:12\nph:23\nMeterial:25\n like that ...\nbut i have problem that when i enter 11/2/2003 date then it display all records which r in db. when i enter another date then its releted records will be filled  so, pls what should i do?

Answer: On your servlet, you can use something similar to validate the date passed:\n\nprotected void doPost(HttpServletRequest request, HttpServletResponse response) {\n\nString date = request.getParameter("date");\n\nif (date == null) || date.equals("")) {\n     throw ServletException("No date parameter specified");\n}\n\ntry {\n     SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");\n     dateFormat.parse(date);\n} catch (ParseException e) {\n     throw new IllegalArgumentException("Cannot parse date: " + date);\n}\n\n     // rest of your servlet code\n}\n\n\nIn addition, use client-side scripting (e.g. JavaScript) on your JSP pages to do validation before form submission.
This question from the Yahoo Q&A forum is categorized in the topic: Business & Finance