2019/12/15学习

 request.setAttribute("name","高春辉");
 out.print( request.getAttribute("name"));

浅谈request.setAttribute
链接二

 <jsp:forward page="delete.jsp"></jsp:forward>
<%
    out.print( request.getSession().getAttribute("name"));
%>

Cookie

<%@ page import="java.net.URLDecoder" %><%--
  Created by IntelliJ IDEA.
  User: gao
  Date: 2019/12/15
  Time: 12:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <%
  request.setCharacterEncoding("GBK");
  request.setCharacterEncoding("GBK");
  String welcome="第一次访问";
  String []info=new String[]{"","",""};
Cookie[]cook=request.getCookies();
  if(cook!=null){
      for(int i=0;i<cook.length;i++){
          if(cook[i].getName().equals("mosoft")){
              String cvalue= URLDecoder.decode(cook[i].getValue());
              info=cvalue.split("#");
                 welcome=",欢迎回来";
          }
      }
  }
  %>
  <%
  String name=info[0];
  %>
  <%=name+welcome%>
  <form action="delete.jsp" method="post">
    <ul>
      <li>姓名:<input type="text" name="name" value="<%=info[0]%>"></li>
      <li>出生日期:<input type="text" name="birthday" value="<%=info[1]%>"></li>
      <li>邮箱地址:<input type="text" name="mail" value="<%=info[2]%>"></li>
      <li><input type="submit" value="提交"></li>
    </ul>
  </form>
  </body>
</html>
<%@ page import="java.net.URLEncoder" %><%--
  Created by IntelliJ IDEA.
  User: gao
  Date: 2019/12/15
  Time: 12:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
   request.setCharacterEncoding("GBK");
   request.setCharacterEncoding("GBK");
   String name=request.getParameter("name");
   String birthday=request.getParameter("birthday");
   String mail=request.getParameter("mail");
   Cookie mycook=new Cookie("mosoft", URLEncoder.encode(name+"#"+birthday+"#"+mail));
   mycook.setMaxAge(60*60*24*365);
   response.addCookie(mycook);
%>
表单提交成功
<%
out.print(name+"<br>"+birthday+"br"+mail);
%>

</body>
</html>

Response

重定向

设置输出缓存

处理HTTP文件头

设置页面自动刷新

<body>
<%response.setHeader("refresh","5");%>
</body>

定时跳转网页

<body>
<%response.setHeader("refresh","5;URL=index.jsp");%>
</body>

点击链接加入群聊【程序员技术交流群】:添加链接描述

发布了84 篇原创文章 · 获赞 24 · 访问量 4332

猜你喜欢

转载自blog.csdn.net/qq_41827511/article/details/103548179
今日推荐