Servlet
response.setContentType("text/html;charset=utf-8");PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
我想问这些句子写在哪比较好,我想写在doPost方法中,这样可以减少每次在调用doPost方法后调用自己写的方法时要多次书写,请问将这些代码写在doPost方法中与我平时写在自己定义的方法有什么不同,哪个比较好????!!!!!如有疑问可参考下面例子
例子1:doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {{
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
if(){
up(request,response);
}else {
del(request,response);
}
out.flush();
out.close();
}
例子2:doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {{
if(){
up(request,response);
}else {
del(request,response);
}
}
public void up(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
//方法体,省略
out.flush();
out.close();
}
[ 本帖最后由 lovemm 于 2009-10-29 19:27 编辑 ]