12.3 Servlet取得内置对象-Session

发表日期:2015-02-15 21:20:08 | 来源: | | 浏览(724) 分类:JSP基础

package demo.canquick.eniac.servlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

public class HttpSessionServletDemo extends HttpServlet {

public void doGet(HttpServletRequest hsr,HttpServletResponse hsrs){

HttpSession hs = hsr.getSession();

System.out.println(hs.getId());

hs.setAttribute("username", "eniac");

System.out.println(hs.getAttribute("username"));

}

public void doPost(HttpServletRequest hsr,HttpServletResponse hsrs){

this.doGet(hsr, hsrs);

}

}

 

 <servlet>

  <servlet-name>servletSession</servlet-name>

  <servlet-class>demo.canquick.eniac.servlet.HttpSessionServletDemo</servlet-class>

 </servlet>

 <servlet-mapping>

  <servlet-name>servletSession</servlet-name>

  <url-pattern>/servletSession</url-pattern>

 </servlet-mapping>


集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。