• 2021-04-14
    阅读下面代码:
    Person 类:
    public class Person {
    private String name;
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    }
    Servlet1:
    request.getSession().setAttribute("name","zhangsan");
    Person p = new Person();
    p.setName("lisi");
    request.getSession().setAttribute("person",p);
    Servlet2:
    String name1 = (String)request.getSession().getAttribute("name");
    Person p = (Person)request.getSession().getAttribute("person");
    response.getWriter().write(name1);
    if(p!=null)response.getWriter().write(p.getName());
    浏览器先访问Servlet1,再去访问Servlet2,输出的结果是:()
  • 举一反三