〇、前情提要
要在servlet中上传一个文件,在文件上传成功后在前端弹出提示框,点击确认后跳转其他页面
参考:
- 在servlet中实现弹出提示框,点击确认后跳转其他页面
https://blog.csdn.net/l18848956739/article/details/62226364 - js 弹出消息框确认是否删除我点否了怎么还是删除了
https://zhidao.baidu.com/question/434372376.html - PrintWriter out = response.getWriter();乱码解决
https://www.cnblogs.com/taiyanhong/p/7510015.html
一、参考
参考:
在servlet中实现弹出提示框,点击确认后跳转其他页面
https://blog.csdn.net/l18848956739/article/details/62226364
PrintWriter out = response.getWriter();
如果成功弹出登陆成功并跳到下一个页面
out.print("<script>alert('登录成功!');window.location.href='跳到登陆成功后的页面'</script>");
如果成功弹出登陆失败并跳到下一个页面
out.print("<script>alert('登录失败!');window.location.href='跳到登陆失败后的页面'</script>");
注意:箭头处不要加分号!!!!
二、测试
servlet里
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.print("<script>alert('删除成功!');window.location.href='all-media.jsp'</script>");
// response.sendRedirect("all-media.jsp");
}
点击关闭后,重定向到想要的页面。
三、在删除前询问
参考:
js 弹出消息框确认是否删除我点否了怎么还是删除了
https://zhidao.baidu.com/question/434372376.html
<a class="anticon anticon-delete" href="meddelete?media_id=<%=m.getMedia_id() %>" onclick="return confirm('确定将此记录删除?')"></a>
οnclick=“return confirm(‘确定将此记录删除?’)”
四、乱码解决
参考:
PrintWriter out = response.getWriter();乱码解决
https://www.cnblogs.com/taiyanhong/p/7510015.html
在response里也要设置utf-8
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
}
版权声明:本文为weixin_43210113原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。