一、out对象://信息送到客户端,生命周期:当前页
javax.servlet.jsp.Jspwriter类的子类的对象
方法:
print() println() write()
格式:
out.print("string");
newLine() //输出换行符
格式:
out.newLine();
flush() //输出缓冲区内容
格式:
out.flush();
close() //关闭输出流
格式:
out.close();
二、response对象:
javax.servlet.http.HttpServletResponse类的子类的对象
方法:
sendRedirect() //重定向
格式:
response.sendRedirect("URL");
setContentType()
格式:
response.setContentType("MIME");
//MIME:text/html(网页),text/plain(文本),application/x-msexcel(Excel文件),application/msword(Word文件)
setHeader()
格式:
response.setHeader("HEADER");
//设置缓冲区
三、request对象:
javax.servlet.HttpServletRequest类的子类的对象
读取表单信息:
格式:
request.getParameter("param");
Enumeration params=request.getParameterNames(); //获取所有的参数名
获取环境变量信息:
编码格式:
默认字符编码:ISO-8859-1
格式:
request.setCharacterEncoding("GBK");
<% //转换字符编码
String str=request.getParameter("param");
byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
%>
四、application对象:
格式:
application.setAttribute(key,obj); //添加属性
application.getAttribute(key); //获取关键字key的对象
application.removeAttribute(key);
五、session对象:
javax.servlet.http.HttpSession类的子类的对象
sessionID:
格式:
session.getId();
自定义属性:
格式:
session.setAttribute(key,obj);
session.getAttribute(key);
session.removeAttribute(key);
六、cookie对象:
格式:
cookie cook=new cookie(name,value);
response.addCookie(cook);
cookie cookies[]=request.getCookies();
cookies[i].getName()
cookies[i].getValue()