所以这是我的servlet代码。我试着将用户输入添加到mysql。 AddEventsServlet.java:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//doGet(request, response);
String title = request.getParameter("title");
String eventDesc= request.getParameter("eventDesc");
<!--Here is my problem, it can't compile cuz Date StartTime and EndTime and Double budget is wrong -->
Date StartTime= request.getParameter("StartTime");
Date EndTime= request.getParameter("EndTime");
Double Budget= request.getParameter("Budget");
}
我在某处看到request.getParameter仅用于String,那么如何将其转换为String?请帮助:)
答案 0 :(得分:0)
这会将字符串转换为日期格式
String StartTimeStr = request.getParameter("StartTime");
String EndTimeStr = request.getParameter("EndTime");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date StartTime = dateFormat.parse(StartTimeStr);
Date EndTime = dateFormat.parse(EndTimeStr);