Which Should i use for date,time,email in servlet?

93 views Asked by At

In servlet we use for text data

String uname=request.getParameter("uname");

For numeric data we use

int contact=Integer.parseInt(request.getParameter("contact"));

Which should i use for email,date and time in servlet?

Actually I'm using HTML5 where I use email as

<input type="email" id="txtEmail" name="email" required>

Date as

<input type="date" id="dateBirthday" name="birthday" required>

Time as

<input type="date" id="dateBirthday" name="birthday" required>

So which should i use in servlet?

2

There are 2 answers

0
Jafar Ali On BEST ANSWER

Servlet api does not provide any special way of getting date and email. getParameter will always get you a String value. It is up to you how you want to treat it.

For date you can work with raw String data or you may want ot parse it in to a Date object as per your convinence. But make sure you know the Date pattern before parsing it.

2
Paul Ngom On

In servlet, the request.getParameter("param") will be a String. So you ca use:

String txtEmail=request.getParameter("email");
String dateBirthday=request.getParameter("birthday");

and depending on your next uses of your variables, you can do conversions as you did for the int variable.