Home>
I am creating an "employee management system" and it is designed to input "birth date" in the format of "YYYY/MM/DD" on the "registration" screen below. If i use this format, the following image error will occur. However, if you enter it in the format of "YYYY-MM-DD", it will be implemented correctly. Where should I change it?
regist_input.jsp
<% @ page language = "java" contentType = "text/html;charset = UTF-8"
pageEncoding = "UTF-8"%>
<% @ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<! DOCTYPE html>
<html>
<head>
<meta http-equiv = "Content-Type" content = "text/html;charset = UTF-8">
<link rel = "stylesheet" href = "<% = request.getContextPath ()%>/css/layout.css" />
<link rel = "stylesheet" href = "<% = request.getContextPath ()%>/css/style.css" />
<title>Employee management system</title>
</head>
<body>
<header>
Employee management system
Welcome, /html/update/update_input.jsp">Jiro Tanaka | Logout
</header>
Employee name search
<form action = "<% = request.getContextPath ()%>/SelectName" method = "post">
<input type = "text" name = "empName" />
<input type = "submit" value = "search" />
</form>
Department search
<form action = "<% = request.getContextPath ()%>/SelectDeptId" method = "post">
<select name = "deptId">
<option value = "1" selected = "selected">Sales Department</option>
<option value = "2">Accounting Department</option>
<option value = "3">General Affairs Department</option>
</select>
<input type = "submit" value = "search" />
</form>
</aside>
Employee registration confirmation screen
Password:
* Hide
Employee name:
${emp.empName}
Gender:
${emp.gender}
Address:
${emp.address}
Birth date:
${emp.birthday}
Permission:
${emp.authority}
Department name:
${emp.dept.deptName}
<form action = "<% = request.getContextPath ()%>/Insert" method = "post">
<input type = "hidden" name = "empPass" value = "${emp.empPass}" />
<input type = "hidden" name = "empName" value = "${emp.empName}" /><input type = "hidden"
name = "gender" value = "${emp.gender}" /><input type = "hidden" name = "address"
value = "${emp.address}" /><input type = "hidden" name = "birthday"
value = "${emp.birthday}" /><input type = "hidden" name = "authority"
value = "${emp.authority}" /><input type = "hidden" name = "deptId" value = "${emp.dept.deptId}" /><input
type = "submit" value = "registration" />
</form>
<form action = "<% = request.getContextPath ()%>/html/regist/regist_input.jsp">
<input type = "submit" value = "return" />
</form>
</article>
<footer>Copyright (C) 2017 System Shared co., ltd, ALL Rights Reserved</footer>
</body>
</html>
package jp.co.sss.crud.servlet;
import java.io.IOException;
import java.sql.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jp.co.sss.crud.bean.Dept;
import jp.co.sss.crud.bean.Emp;
import jp.co.sss.crud.db.DeptDao;
import jp.co.sss.crud.db.EmpDao;
@WebServlet ("/ Insert")
public class Insert extends HttpServlet {
protected void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding ("UTF-8");
String empPass = request.getParameter ("empPass");
String empName = request.getParameter ("empName");
String gender = request.getParameter ("gender");
String address = request.getParameter ("address");
String birthday = request.getParameter ("birthday");
String authority = request.getParameter ("authority");
String deptId = request.getParameter ("deptId");
Dept dept = DeptDao.findById (deptId);
Emp emp = new Emp ();
emp.setEmpPass (empPass);
emp.setEmpName (empName);
emp.setGender (Integer.parseInt (gender));
emp.setAddress (address);
emp.setBirthday (Date.valueOf (birthday));
emp.setAuthority (Integer.parseInt (authority));
emp.setDept (dept);
EmpDao.insert (emp);
request.getRequestDispatcher ("/ html/regist/regist_complete.jsp"). forward (request, response);
}
}
-
Answer # 1
-
Answer # 2
The simple thing is to replace the slash in the birthday string with a hyphen?
String birthday = request.getParameter ("birthday"). replace ("/", "-");
Related articles
- java - about output of standard input (3 lines or more)
- java - about localhost
- about java version
- java - about screen display in struts2
- i have a question about a simple problem with [java] files
- about symbolic key input in unity
- about the argument of zipentry (java: jdk16)
- java - about the minus of the method
- java - about nullpointerexception
- about n/a at the time of batch input to cells of vba one-dimensional array
- python 3x - about text box input
- java - about the two arguments of onclick
- [java] about equals method (reason why nullpointerexception does not occur even if null is passed/override)
- java - about the stringutilsisempty () method
- beginners about the development of java spring tool suite
- java - about js that displays images randomly
- about java jdk download
- i want to store java spring input values in a list of form classes
- python - input data format when implementing multivariate lstm by keras
- java create an array from arbitrary input
Related questions
- java - how to select the one that matches the value obtained from springmvc db?
- java : Exception while connecting to remote Oracle DB
- how to implement "like function" in servlet, java, postgresql?
- java - 404 error when updating to struts 2525
- java - i don't know how to get log4j running in my application
- i want to pass a character string from java servlet to jsp and display it
- java - i want to leave the initial value of the radio button unselected
- java - how to display background image in jsp
- java - on the login screen, if the login is successful, i want to move to another jsp page
- java - i get a message saying that i can't forward after committing the response
(docs.oracle.com) Date valueOf ()
So why not replace
/
with-
asbirthday.replace ("/", "-")
?The best one is "Convert properly".