jsp页面往后台存储时间类型数据时发生错误Unknown Source

主要问题是前台使用mobiscroll控件写入input控件后 使用form submit提交数据
后台servlet使用getParameter获取input控件值 转换格式后传输到数据库中。数据库字段为mysql的date类型
但是现在报错显示at java.text.SimpleDateFormat.parse(Unknown Source) at java.text.DateFormat.parse(Unknown Source

附上代码 servlet:

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      doGet(request, response);

      System.out.println("进来了submit!!!!");
      work worksubmit=new work();
      HttpSession session = request.getSession();
      worksubmit.sete_name("sjn");
      //(String)session.getAttribute("username");
      SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd");// 定义格式
      String choosedate=dd.format(request.getParameter("txttest"));
      System.out.println(choosedate);
      Date chooseDate = null;
      try {
        chooseDate = dd.parse(choosedate);
    } catch (ParseException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
      java.sql.Date sqlchooseDate = new java.sql.Date(chooseDate.getTime());
      worksubmit.setw_date(sqlchooseDate);//change 日期格式

      String testname=(String)request.getParameter("testname");
      worksubmit.setw_title(testname);
      ///time 获得方式待写
      int score =0;
      String content=(String)request.getParameter("feel");//心得内容
      if(content != null)
      {
          score+=2;
      }
      worksubmit.setw_content(content);

      int achieve11=0;
      int achieve21=0;
      int achieve31=0;
      int achieve41=0;
      String achieve1=(String)request.getParameter("Fruit1");
      String achieve2=(String)request.getParameter("Fruit2");
      String achieve3=(String)request.getParameter("Fruit3");
      String achieve4=(String)request.getParameter("Fruit4");
      if (achieve1!= null)
      {
          score=score+2;
          achieve11=1;
      }
      if (achieve2!= null)
      {
          score=score+2;
          achieve21=1;
      }
      if (achieve3!= null)
      {
          score=score+2;
          achieve31=1;
      }
      if (achieve4!= null)
      {
          score=score+2;
          achieve41=1;
      }
      worksubmit.setachieve1(achieve11);
      worksubmit.setachieve2(achieve21);
      worksubmit.setachieve3(achieve31);
      worksubmit.setachieve4(achieve41);
      worksubmit.setw_score(score);

      DAOProxy DAOProxy=new DAOProxy();
         try {
             if(DAOProxy.submit(worksubmit)){
                 request.getRequestDispatcher("worklist.jsp").forward(request,response);;
                 return ;
            }else {
                return ;
            }

            } catch (Exception e) {
                e.printStackTrace();
            }


    }

前台jsp页面:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">

    <title>日期选择</title>
    <!-- 引入JQ Mobile所需C2S -->
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
    <!-- 引入JQ 脚本文件提高对 JQmobile支持 -->
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <!-- 引入JQ Mobile所需脚本文件 -->
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <!-- 引入mobiscroll插件 -->
    <script src="js/zepto.js" type="text/javascript"></script> 
    <script src="plugs/mobiscroll/js/mobiscroll.zepto.js" type="text/javascript"></script> 
    <script src="plugs/mobiscroll/js/mobiscroll.core.js" type="text/javascript"></script>
    <script src="plugs/mobiscroll/js/mobiscroll.scroller.js" type="text/javascript"></script>
    <script src="plugs/mobiscroll/js/mobiscroll.datetime.js" type="text/javascript"></script>
    <script src="plugs/mobiscroll/js/mobiscroll.select.js" type="text/javascript"></script>
    <script src="plugs/mobiscroll/js/mobiscroll.scroller.ios.js" type="text/javascript"></script>
    <script src="plugs/mobiscroll/js/mobiscroll.scroller.android.js" type="text/javascript"></script>
    <script src="plugs/mobiscroll/js/mobiscroll.scroller.android-ics.js" type="text/javascript"></script>
    <script src="plugs/mobiscroll/js/mobiscroll.scroller.wp.js" type="text/javascript"></script>
    <script src="plugs/mobiscroll/js/mobiscroll.i18n.zh.js" type="text/javascript"></script>
    <link href="plugs/mobiscroll/css/mobiscroll.scroller.css" rel="stylesheet" type="text/css" />
    <link href="plugs/mobiscroll/css/mobiscroll.scroller.sense-ui.css" rel="stylesheet" type="text/css" />
    <!-- 配置mobiscroll插件 -->
    <script type="text/javascript">
        $(function () {
            var curr = new Date().getFullYear();

            var fun = function () {
                $('#txttest').scroller('destroy').scroller({
                    preset: 'date',
                    minDate: new Date(2012, 3, 10),
                    maxDate: new Date(2020, 12, 15),
                    invalid: { daysOfWeek: [0, 6], daysOfMonth: ['5/1', '12/24', '12/25'] },
                    theme: $('#theme').val(),
                    lang: 'zh'
                });
            }
            $('.settings select').bind('change', function () {
                fun();
            });
            fun();
        });
    </script>

</head>

<body>
     <div data-role="page" data-theme="a">
     <div data-role="header" data-position="fixed">
        <h1>写作业</h1>
        <a href="http://localhost:8080/zhisland/plugs/mobiscroll/index.html" data-role="button"  class="ui-btn-left">返回</a>
     </div>

     <form action="submitServlet" method="post">
     <div id="choose" name="choose" data-role="content"> 
         <label for="test" >选择日期:</label>
     </div>
     <div id="inputchoose"> 
         <input name="txttest"  id="txttest"  placeholder="请选择日期" >
     </div>
     <style type="text/css">
         #choose{ width:100px; float:left;}
         #inputchoose{ width:200px;float:left;}
     </style> 

<HR style="border:1 dashed #987cb9" width="100%" color=#987cb9 SIZE=1>

     <div id="learn" data-role="content"> 
         <label for="test" >学习文章:</label>
     </div>
     <div id="inputlearn"> 
         <input name="testname"  id="testname"  placeholder="请填写学习文章题目" >
     </div>
     <style type="text/css">
         #learn{ width:100px; float:left;}
         #inputlearn{ width:400px;float:left;}
     </style> 

<HR style="border:1 dashed #987cb9" width="100%" color=#987cb9 SIZE=1>

     <div data-role="content" >
     <label for="name">心得体会:</label>
     <textarea   id="feel" name="feel" style=" "></textarea> 
     <!-- 禁止textarea自动增长 -->
     <script>$(function () { $("#feel").textinput("option", "autogrow", false); })</script>
     </div>
     <style> textarea.ui-input-text{min-height:200px;}</style>

<HR style="border:1 dashed #987cb9" width="100%" color=#987cb9 SIZE=1>

     <div data-role="content" >
     <label >自我评价:</label>
     <label for="1">1.听导读分享<input name="Fruit1" type="checkbox" value="1" /></label>
     <label for="2">2.不抱怨 不说累 尽己责<input name="Fruit2" type="checkbox" value="2" /></label>
     <label for="3">3.看家书点评<input name="Fruit3" type="checkbox" value="3" /></label>
     <label for="4">4.诵读课文<input name="Fruit4" type="checkbox" value="4" /></label>
     </div>
     <input type="submit" value="确定">
 </form>
     <div data-role="footer" data-position="fixed">
        <div data-role="navbar" data-position="fixed">
           <ul>
              <li>
             <a href="http://localhost:8080/zhisland/plugs/mobiscroll/index.html">
             <h3>
                                      创建作业
             </h3>
             </a>
             </li>
           </ul>
        </div>



</body>
</html>

麻烦高手解决一下 第一次做,还不太懂。十分感谢!!

3个回答

我尝试成功 是格式转换问题

Unknown Source是因为是反射调用的,不能确定调用者,并不是真正的错误信息。你还是需要调试你的程序,特别是数据库连接、数据类型是否匹配、sql、参数这些特别容易错的地方

String choosedate=dd.format(request.getParameter("txttest")); 获取到的数据格式不正确

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!