2016-11-03 13 views
0

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">&nbsp&nbsp<input type="reset" name="reset" value="Reset"></td> 

       </tr> 
     </table> 
    <br/> 

    </form> 
    </center> 

    </body> 
    </html> 

leaveservlet件名、内容は、からとまでこのサーブレットに掲載されますし、私はて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; 
} 

例外Exception thrown on browser

答えて

0

この問題は、あなたがこれらのフィールドに入力ページから送信されている不正なデータ(using SQL reserved/syntax keywords 'from' 'select' ,etc..)で来る:

subject, content, from 

subject = subjectA、content = contentB、from = FROMUSのような単純なデータを設定してみてください

関連する問題