protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); Category category = new Category(); category.add(new String(request.getParameter("name").getBytes("iso-8859-1"), "utf-8")); response.getWriter().println("<script>alert('添加成功');window.location.href='admin/category.jsp'</script>"); }我这里是用window.location.href 脚本操作返回页面。这样合理吗?
1 回答

qq_遁去的一_1
TA贡献1725条经验 获得超7个赞
不可以,这是js代码当运行在浏览器里,如果要回到表单页面,可以使用楼上的那种方式,或者请求转发,但是需要指定路径,属于服务器请求。
如果在页面使用js提交表单,则无需这么麻烦
添加回答
举报
0/150
提交
取消