この記事ではServletの中で頻繁に使用されるクラスとメソッドについて自分が見やすいようにまとめた。
JSP
ファイルを挿入
<%@ include file="footer.jsp"%>
スコープ一覧
(HttpServletRequest)リクエスト ... request.setAttribute("key", sample); (HttpSession)セッション ... session.setAttribute("key", sample); (ServletContext)アプリケーション ... context.setAttribute("key", sample);
EL式
取得(脆弱性あり)
${key.id}
スコープ指定の取得
${requestScope.key} ${sessionScope.key} ${contextScope.key}
JSTL
タグリブ起動
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
出力
<c:out value="${name}"/>
if文
<c:if test="${条件}"> //TODO </c:if>
foreach構文
<c:forEach var="sample" items="${samples}"> //TODO </c:forEach>
choose構文
<c:choose> <c:when key="${条件}"> //TODO </c:when> <c:when key="${条件}"> //TODO </c:when> <c:otherwise> //TODO </c:otherwise> </c:choose>