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
 

 }

}


用session保持一个数组import java.io.IOException;
用session保持一个数组
import java.io.PrintWriter;
用session保持一个数组
import java.util.ArrayList;
用session保持一个数组
用session保持一个数组
import javax.servlet.ServletException;
用session保持一个数组
import javax.servlet.http.HttpServlet;
用session保持一个数组
import javax.servlet.http.HttpServletRequest;
用session保持一个数组
import javax.servlet.http.HttpServletResponse;
用session保持一个数组
import javax.servlet.http.HttpSession;
用session保持一个数组

相关文章:

  • 2021-06-26
  • 2022-02-09
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2021-09-06
  • 2021-08-17
  • 2022-01-11
  • 2022-12-23
相关资源
相似解决方案