java 内置对象

response 常用方法
addCookie(Cookie cookie) 向客户端增加COOKIE
setHeader(String name,Strin  value)设置回应的头信息
senRedirect(String location) 页面跳转

设置头信息:
 所有 的头信息都 随前瞻请求和回应自动发送到服务器端(客户端)
    response.setHeader("refresh","3;URL=HELLO.jsp"); 3秒后定时跳转到HELLO页面
    html 头信息设置跳转:<meta http-equiv="refresh" content="3;url=hello.jsp"> 客户端跳转
    response.sendRedirect("HELLO.jsp");
    response.sendRedirect 与forward 跳转
       1.response.sendRedirect 客户端跳转,request无法传值。sendRedirct后代码继续执行
         forward 服务端跳转,request可以传值后面代码不执行。
    Cookie
        Cookie c1=new Cookie("wadenin","001");
    Cookie c2=new Cookie("l00","002");
      c1.setMaxAge(100);

        Cookie c[]=request.getCookies();
    for(int i=0;i<c.length;i++){

     <h3><%=c[i].getName()%>-----><%=c[i].getValue()%></h3>

     }
   session接口方法
getId() 获取session ID
getCreationTime() 获取seeson创建时间
getLastAccessedTime() 取得session最后一次操作时间。
isNew() 判断是不是新SESSION
INVALIDATE() 让session失效。
getAttributeNames()  得到全部属性的名称。
session用得最多的地方,登录注销
判断新用户。

application 方法
掌握application  和getServletContext()方法联系;网站计数器
  getRealPath()得到虚拟目录对应的绝对路径
  Enumeration getAttributeNames() 得到所有属性的名称
  getContextPath() 取得当前的虚拟路径名称





  <%
     request.setCharacterEncoding("utf-8");
    
     String name=request.getParameter("name");
     String info=request.getParameter("info");
    
     String path=this.getServletContext().getRealPath("/")+"text"+name;
    
     File file=new File(path);
     PrintStream ps=null;
     ps=new PrintStream(new FileOutputStream(file));
     ps.println(info);
     ps.close();
   %>
   
   <%
    Scanner scan=new Scanner(new FileInputStream(path));
    StringBuffer sb=new StringBuffer();
    while(scan.hasNext())
    {
    sb.append(scan.next()).append("</br>");
    }
    scan.close();
   %>
   
   <%=sb%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值