use of com.zyf.bean.Suggestion in project HeartWatchdogJsp by Viczyf.
the class SuggestionServlet method saveSuggestion.
public void saveSuggestion(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
Suggestion sugg = new Suggestion();
sugg.setUid(user.getUid());
sugg.setUname(user.getUname());
Date now = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String date = format.format(now);
System.out.println(date);
sugg.setDate(date);
String info = request.getParameter("info");
sugg.setSuggsetion(info);
SuggestionDao suggestiondao = new SuggestionDao();
boolean rs = suggestiondao.saveSuggestion(sugg);
if (rs) {
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.print("<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + " <meta charset=\"UTF-8\">\n" + " <link href=\"css/sweet-alert.css\" rel=\"stylesheet\">\n" + "</head>\n" + "<body>\n" + "<script src=\"js/jquery-3.1.1.js\"></script>\n" + "<script src=\"js/sweet-alert.min.js\"></script>\n" + "<script type=\"text/javascript\">\n" + " $(document).ready(function(){\n" + " swal({\n" + " type:\"success\",\n" + " title: \"提交成功,感谢您的支持\",\n" + " text: '<a href=\"suggestion.jsp\" role=\"button\"><font size=\"5\" color=\"green\"> 点此返回</font></a>。<br>3秒后自动返回。',\n" + " animation:\"slide-from-top\",\n" + " html: true,\n" + " timer: 3000,\n" + " showConfirmButton: false\n" + " });\n" + " })\n" + " window.onload = function(){\n" + " setTimeout(fun,3000);\n" + " }\n" + " function fun(){\n" + " window.location=\"suggestion.jsp\"\n" + " }\n" + "</script>\n" + "</body>\n" + "</html>");
out.flush();
out.close();
} else {
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.print("<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + " <meta charset=\"UTF-8\">\n" + " <link href=\"css/sweet-alert.css\" rel=\"stylesheet\">\n" + "</head>\n" + "<body>\n" + "<script src=\"js/jquery-3.1.1.js\"></script>\n" + "<script src=\"js/sweet-alert.min.js\"></script>\n" + "<script type=\"text/javascript\">\n" + " $(document).ready(function(){\n" + " swal({\n" + " type:\"error\",\n" + " title: \"提交失败\",\n" + " text: '<a href=\"suggestion.jsp\" role=\"button\"><font size=\"5\" color=\"green\"> 点此返回</font></a>。<br>3秒后自动返回。',\n" + " animation:\"slide-from-top\",\n" + " html: true,\n" + " timer: 3000,\n" + " showConfirmButton: false\n" + " });\n" + " })\n" + " window.onload = function(){\n" + " setTimeout(fun,3000);\n" + " }\n" + " function fun(){\n" + " window.location=\"suggestion.jsp\"\n" + " }\n" + "</script>\n" + "</body>\n" + "</html>");
out.flush();
out.close();
}
}
Aggregations