servlet中的六大标准对象

版权声明:hxt未经允许不可转载 https://blog.csdn.net/weixin_42979840/article/details/82859174
/*---------------------------------------------------------------*/
		// *****防止乱码的解决方案
		// 输入数据乱码解决方案:使用request对象获取浏览器提交数据前,先设置字符集
		request.setCharacterEncoding("utf-8");
		// 输出数据乱码解决方案,使用request输出数据前,先设置字符集和内容类型
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");

		/* servlet的doxxxx方法中的6个标准对象 (包含request和response) */
		// 从request中获取session对象和application对象
		HttpSession session = request.getSession();
		ServletContext application = request.getServletContext();
		// 调用继承的方法来获取config对象
		ServletConfig config = getServletConfig();
		// 从response对象里获取out对象 ———response.getWriter()之前,要先设置页面的编码
		java.io.PrintWriter out = response.getWriter();
		/*-------------------------------------------------------------*/

猜你喜欢

转载自blog.csdn.net/weixin_42979840/article/details/82859174