Leave.jsp Jsp页面申请休假。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<head>
<title>
Leave Apply</title>
<style>
body {
font-family: Times New Roman;
font-size: 200%;
}
table {
border: 0px;
font-family: Time New Roman;
font-size: 50%;
width: 30%;
background-color: orange;
padding: 15px;
}
</style>
</head>
<body >
<center>
Apply Leave<br/><br/>
<form method="post" action="leaveservlet" name="form1">
<table>
<tr>
<td>
Subject:
</td>
<td>
<input type="text" name="name" placeholder="Subject">
</td>
</tr>
<tr>
<td>
Content:
</td>
<td>
<textarea name="content" rows="8" cols="30"></textarea>
</td>
</tr>
<tr>
<td>
From:
</td>
<td>
<input type="date" name="from">
</td>
</tr>
<tr>
<td>
Till:
</td>
<td>
<input type="date" name="till">
</td>
</tr>
<input type="hidden" name="status" value="0">
<tr>
<td></td>
<td><input type="submit" name="submit" value="Leave Apply">  <input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
<br/>
</form>
</center>
</body>
</html>
leaveservlet 主题,内容,来自和直到发布到此servlet,然后我使用SimpleDateFormat解析字符串到目前为止。
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
PrintWriter out= response.getWriter();
String sub= request.getParameter("name");
String con= request.getParameter("content");
String from= request.getParameter("from");
String till= request.getParameter("till");
String status= request.getParameter("status");
int i = Integer.parseInt(status);
Session s= HibernateUtil.getSessionFactory().openSession();
Transaction t= s.beginTransaction();
Leave l= new Leave();
l.setSubject(sub);
l.setContent(con);
try{
l.setFrom(fmt.parse(from));
l.setTill(fmt.parse(till));
}
catch(Exception e){
out.print("sorry");
}
l.setStatus(i);
s.save(l);
t.commit();
s.close();
}
Leave.java
public class Leave implements java.io.Serializable {
private Integer id;
private String subject;
private String content;
private Date from;
private Date till;
private Integer status;
public Leave() {
}
public Leave(String subject, String content, Date from) {
this.subject = subject;
this.content = content;
this.from = from;
}
public Leave(String subject, String content, Date from, Date till, Integer status) {
this.subject = subject;
this.content = content;
this.from = from;
this.till = till;
this.status = status;
}
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSubject() {
return this.subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return this.content;
}
public void setContent(String content) {
this.content = content;
}
public Date getFrom() {
return this.from;
}
public void setFrom(Date from) {
this.from = from;
}
public Date getTill() {
return this.till;
}
public void setTill(Date till) {
this.till = till;
}
public Integer getStatus() {
return this.status;
}
public void setStatus(Integer status) {
this.status = status;
}
答案 0 :(得分:0)
出现此问题的原因是您从这些字段的“输入”页面发送的数据(using SQL reserved/syntax keywords 'from' 'select' ,etc..)
不正确:
subject, content, from
尝试设置一些简单数据,例如subject = subjectA,content = contentB,from = FROMUS