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("");
}
我这里是用window.location.href 脚本操作返回页面。这样合理吗?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
response.sendRedirect()
不可以,这是js代码当运行在浏览器里,如果要回到表单页面,可以使用楼上的那种方式,或者请求转发,但是需要指定路径,属于服务器请求。
如果在页面使用js提交表单,则无需这么麻烦