zoukankan      html  css  js  c++  java
  • 用session保持一个数组

    public class Person {
     
       private  String empname="";
       private  String empno="";
      
      public void setEmpName(String empname)
      {
         this.empname=empname;
      }
     
      public String getEmpName()
      {
        return this.empname;
      }
     
     
      public void setEmpNo(String empno)
      {
          this.empno=empno;
      }
     
      public String getEmpNo()
      {
         return this.empno;
      }
     

    }

    public class Person {
     
       
    private  String empname="";
       
    private  String empno="";
       
      
    public void setEmpName(String empname)
      
    {
         
    this.empname=empname;
      }

      
      
    public String getEmpName()
      
    {
        
    return this.empname;
      }

      
      
      
    public void setEmpNo(String empno)
      
    {
          
    this.empno=empno;
      }

      
      
    public String getEmpNo()
      
    {
         
    return this.empno;
      }

     

    }

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    public class listpage extends HttpServlet {
     private static final long serialVersionUID = 2L;
     /**
      * Constructor of the object.
      */
     public listpage() {
      super();
     }

     /**
      * Destruction of the servlet. <br>
      */
     public void destroy() {
      super.destroy(); // Just puts "destroy" string in log
      // Put your code here
     }

     /**
      * The doGet method of the servlet. <br>
      *
      * This method is called when a form has its tag value method equals to get.
      *
      * @param request the request send by the client to the server
      * @param response the response send by the server to the client
      * @throws ServletException if an error occurred
      * @throws IOException if an error occurred
      */
     public void doGet(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {

      response.setContentType("text/html;charset=gb2312");
      PrintWriter out = response.getWriter();
      out
        .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
      out.println("<HTML>");
      out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
      out.println("  <BODY>");
      out.print("    This is ");
      out.print(this.getClass());
      out.println(", using the GET method<br>");
      ArrayList resultlist = new ArrayList();
      Person person = new Person();
            person.setEmpNo("编码");
            person.setEmpName("名字");
            resultlist.add(person);
            Person person1=(Person)resultlist.get(0);
         out.println(person1.getEmpName());
         HttpSession session = request.getSession();
         session.setAttribute("Mysession",new ArrayList(resultlist));
         ArrayList all = (ArrayList) session.getAttribute("Mysession");
         Person person2=(Person)all.get(0);
         out.println("<br>");
         out.println(person2.getEmpNo());
      out.println("  </BODY>");
      out.println("</HTML>");
      out.flush();
      out.close();
     }

     /**
      * The doPost method of the servlet. <br>
      *
      * This method is called when a form has its tag value method equals to post.
      *
      * @param request the request send by the client to the server
      * @param response the response send by the server to the client
      * @throws ServletException if an error occurred
      * @throws IOException if an error occurred
      */
     public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {

      response.setContentType("text/html;charset=gb2312");
      PrintWriter out = response.getWriter();
      out
        .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
      out.println("<HTML>");
      out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
      out.println("  <BODY>");
      out.print("    This is ");
      out.print(this.getClass());
      out.println(", using the POST method");
      out.println("  </BODY>");
      out.println("</HTML>");
      out.flush();
      out.close();
     }

     /**
      * Initialization of the servlet. <br>
      *
      * @throws ServletException if an error occure
      */
     public void init() throws ServletException {
      // Put your code here
     

     }

    }


    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.ArrayList;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    public class listpage extends HttpServlet {
        
    private static final long serialVersionUID = 2L;
        
    /**
         * Constructor of the object.
         
    */

        
    public listpage() {
            
    super();
        }


        
    /**
         * Destruction of the servlet. <br>
         
    */

        
    public void destroy() {
            
    super.destroy(); // Just puts "destroy" string in log
            
    // Put your code here
        }


        
    /**
         * The doGet method of the servlet. <br>
         *
         * This method is called when a form has its tag value method equals to get.
         * 
         * 
    @param request the request send by the client to the server
         * 
    @param response the response send by the server to the client
         * 
    @throws ServletException if an error occurred
         * 
    @throws IOException if an error occurred
         
    */

        
    public void doGet(HttpServletRequest request, HttpServletResponse response)
                
    throws ServletException, IOException {

            response.setContentType(
    "text/html;charset=gb2312");
            PrintWriter out 
    = response.getWriter();
            out
                    .println(
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
            out.println("<HTML>");
            out.println(
    "  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
            out.println(
    "  <BODY>");
            out.print(
    "    This is ");
            out.print(
    this.getClass());
            out.println(
    ", using the GET method<br>");
            ArrayList resultlist 
    = new ArrayList();
            Person person 
    = new Person();
            person.setEmpNo(
    "编码");
            person.setEmpName(
    "名字");
            resultlist.add(person);
            Person person1
    =(Person)resultlist.get(0);
            out.println(person1.getEmpName());
            HttpSession session 
    = request.getSession();
            session.setAttribute(
    "Mysession",new ArrayList(resultlist));
            ArrayList all 
    = (ArrayList) session.getAttribute("Mysession");
            Person person2
    =(Person)all.get(0);
            out.println(
    "<br>");
            out.println(person2.getEmpNo());
            out.println(
    "  </BODY>");
            out.println(
    "</HTML>");
            out.flush();
            out.close();
        }


        
    /**
         * The doPost method of the servlet. <br>
         *
         * This method is called when a form has its tag value method equals to post.
         * 
         * 
    @param request the request send by the client to the server
         * 
    @param response the response send by the server to the client
         * 
    @throws ServletException if an error occurred
         * 
    @throws IOException if an error occurred
         
    */

        
    public void doPost(HttpServletRequest request, HttpServletResponse response)
                
    throws ServletException, IOException {

            response.setContentType(
    "text/html;charset=gb2312");
            PrintWriter out 
    = response.getWriter();
            out
                    .println(
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
            out.println("<HTML>");
            out.println(
    "  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
            out.println(
    "  <BODY>");
            out.print(
    "    This is ");
            out.print(
    this.getClass());
            out.println(
    ", using the POST method");
            out.println(
    "  </BODY>");
            out.println(
    "</HTML>");
            out.flush();
            out.close();
        }


        
    /**
         * Initialization of the servlet. <br>
         *
         * 
    @throws ServletException if an error occure
         
    */

        
    public void init() throws ServletException {
            
    // Put your code here
        

        }


    }

  • 相关阅读:
    css 两边是线,中间文字的多种实现方法
    vue provide/inject 父组件如何给孙子组件传值
    Mac版本的 Axure rp8 不显示菜单栏
    mac 如何卸载node和npm采坑之旅
    css3 鼠标悬停图片动画
    css3 一个六边形 和 放大旋转动画DEMO演示
    js drag drop 收藏夹拖拽移除的简单例子
    css 折角效果/切角效果
    css 给图片添加滤镜效果,透明层毛玻璃效果
    c# udp通讯实现
  • 原文地址:https://www.cnblogs.com/chinatefl/p/1182008.html
Copyright © 2011-2022 走看看