LoginSignup
2
2

More than 3 years have passed since last update.

Servlet Sessionについて

Posted at

Session

  • セッションはクライアントごとに作成される。
  • HttpServletRequestインターフェースで用意されているgetSessionメソッドを用いて生成する。
  • getSessionメソッドは、すでにセッションが開始されていればそのセッションを返す。
    • 引数がtrue:セッションが開始されてない場合、新しいセッションを返す。
    • 引数がfalse:セッションが開始されてないばあ、nullを返す。

サンプル

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

  HttpSession session = request.getSession(true);
  session.setAttribute("hoge", "1");
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2