0
0

More than 3 years have passed since last update.

【Java・JSP】暗黙オブジェクト

Posted at

暗黙オブジェクト

一言まとめ

宣言なしでJSP内で使用できるオブジェクト

【説明】

javaでは system.out.println() と記述するだけで値の出力が可能ですが、
jspでも同じ様に、特別な宣言を行わずout.print()と記述すれば値の出力が行えます。
こういった、宣言無しで最初から利用できるオブジェクトが暗黙オブジェクトです。

【特徴】

暗黙オブジェクトの簡単な利用方法は以下です。

オブジェクト名 説明
request クライアントからのリクエストを取得する
response クライアントへのレスポンスを設定する
out JSPの実行結果をクライアントへの出力する
pageContext JSPのオブジェクトを管理する
session セッション情報を管理する
application アプリケーションデータを管理する
page JSPページ自身を表す。「this」と同じ
config JSPページのパラメータを設定する
exception 例外発生時のエラー情報を取得する

【使用場面】

【使用方法】

【implict_object.jsp】

こちらは日付を表示するJSPのプログラムです。

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,java.text.SimpleDateFormat"%>
<html>
<head>
<title>sample_1</title>
</head>
<body>
  <div>
   <% Date date = new Date();
      SimpleDateFormat sdf = new SimpleDateFormat("本日はyyyy年 MM月 dd日");
      String formatDate = sdf.format(date);

   out.print(formatDate); %><!-- out.printで画面に出力する -->
  </div>
</body>
</html>

【出力結果(ブラウザ)】

本日は2020年 12月 04日

【まとめ】

参考文献・記事

0
0
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
0
0