「Java/Tomcat/Tomcatメモ」の編集履歴(バックアップ)一覧はこちら
追加された行は緑色になります。
削除された行は赤色になります。
* ■目次
#contents(fromhere=true)
* ■Servlet & JSP
** ServletからJSPにパラメータを渡す
>request.setAttribute("string", "文字列を渡す");
** Servletから受け取ったパラメータを利用する
><%= request.getAttribute("string") %>
* ■Servlet
* ■JSP
** ページの文字コードを設定する
><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
><%@ page language="java" contentType="text/html; charset=Shift_JIS" pageEncoding="Shift_JIS" %>
><%@ page language="java" contentType="text/html; charset=EUC_JP" pageEncoding="EUC_JP" %>
- ページディレクティブはJSPファイルの先頭に記述します。
- JSPファイルの文字コードも同じ文字コードにしておいたほうが無難です。
** htmlに変数やオブジェクトを出力する
><%= hogehoge %>
** クラスやパッケージをインポートする
- java.utilパッケージをインポート
><%@ page import="java.util.*" %>
- 自作Beanをインポート
><%@ page import="my.package.MyBean" %>
** コンテキストパスを出力する
-<%=request.getContextPath()%>
-- → /ContextPath
-<form action='<%=request.getContextPath()%>/hogeservlet' method="post">
-- → <form action='/ContextPath/hogeservlet' method="post">
* ■html
** ページの文字コードをブラウザに伝える
><meta http-equiv="Content-Type" content="text/html; charset="UTF-8">
><meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
><meta http-equiv="Content-Type" content="text/html; charset="EUC_JP">
* ■目次
#contents(fromhere=true)
* ■Servlet & JSP
** ServletからJSPにパラメータを渡す
>request.setAttribute("string", "文字列を渡す");
** Servletから受け取ったパラメータを利用する
><%= request.getAttribute("string") %>
* ■Servlet
** 文字コードやコンテンツタイプを指定する
response.setContentType("text/html; charset=UTF-8");
response.setContentType("image/png");
response.setContentType("image/jpeg");
response.setContentType("image/gif");
* ■JSP
** ページの文字コードを設定する
><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
><%@ page language="java" contentType="text/html; charset=Shift_JIS" pageEncoding="Shift_JIS" %>
><%@ page language="java" contentType="text/html; charset=EUC_JP" pageEncoding="EUC_JP" %>
- ページディレクティブはJSPファイルの先頭に記述します。
- JSPファイルの文字コードも同じ文字コードにしておいたほうが無難です。
** htmlに変数やオブジェクトを出力する
><%= hogehoge %>
** クラスやパッケージをインポートする
- java.utilパッケージをインポート
><%@ page import="java.util.*" %>
- 自作Beanをインポート
><%@ page import="my.package.MyBean" %>
** コンテキストパスを出力する
-<%=request.getContextPath()%>
-- → /ContextPath
-<form action='<%=request.getContextPath()%>/hogeservlet' method="post">
-- → <form action='/ContextPath/hogeservlet' method="post">
* ■html
** ページの文字コードをブラウザに伝える
><meta http-equiv="Content-Type" content="text/html; charset="UTF-8">
><meta http-equiv="Content-Type" content="text/html; charset="Shift_JIS">
><meta http-equiv="Content-Type" content="text/html; charset="EUC_JP">
- Headタグの内側に記述します。