getWriter():回送字符;
OutPutStream():回送二进制数据和字符串;
PrintWriter out = response.getWriter(); out.println("hello,world!"); OutputStream os = response.getOutputStream(); os.write("hello,world!".getBytes());
//这两者不能同时使用!!!!
获取请求的信息
//java的静态全局变量 public static String name; //或者这样,多个信息之间用&隔开,不能传对象 response.sendRedirect("/web/servlet?username="+username+"&pwd="+password); String username = request.getParameter("username"); //使用session传递,可以传字符串,也可以传对象 request.getSession().setAttribute("password", password); String password = (String) request.getSession().getAttribute("password"); //传对象 User user = new User(username,password); request.getSession().setAttribute("user", user); User user = (User) request.getSession().getAttribute("user");