package validation;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import javax.servlet.*;
import javax.servlet.http.*;
public class ValidationServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
boolean passed = validateDate(request.getParameter("birthDate"));
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
String message = "You have entered an invalid date.";
if (passed) { message = "You have entered a valid date.“; }
out.println("<response>");
out.println("<passed>" + Boolean.toString(passed) + "</passed>");
out.println("<message>" + message + "</message>");
out.println("</response>");
out.close();
}
private boolean validateDate(String date) {
boolean isValid = true;
if(date != null) {
SimpleDateFormat formatter= new SimpleDateFormat("MM/dd/yyyy");
try {
formatter.parse(date);
} catch (ParseException pe) {
System.out.println(pe.toString());
isValid = false;
}
} else { isValid = false; }
return isValid;
}
}
'자바 > JAVA...Spring' 카테고리의 다른 글
DynamicUpdateServlet.java (0) | 2015.12.29 |
---|---|
dynamicUpdate.html (0) | 2015.12.29 |
[/Web-INF/web.xml] (0) | 2015.12.28 |
[form_test.html] (0) | 2015.12.28 |
[ajax_test.html] (0) | 2015.12.24 |