우선 JSTL 라이브러리를 여기에서 다운로드한 후에, WEB-INF/lib 디렉토리에 복사한다.
- jstl-api-1.2.jar
- jstl-impl-1.2.jar
그리고 JSTL을 사용하는 JSP 앞쪽에 다음 내용을 추가한다.
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
* sql, xml, fmt 태그 등도 비슷한 방법으로 사용한다.
그런데 JSP가 임의의 클래스를 상속하는 경우에는 c:forEach 태그가 정상적으로 동작하지 않을 수 있다. 이를 해결하려면 JSP 상위 클래스에서 ServletConfig를 올바르게 처리해야 한다.
package com.dimdol.web;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.HttpJspPage;
public abstract class BasePage implements HttpJspPage {
private ServletConfig config;
public ServletConfig getServletConfig() {
return config;
}
public String getServletInfo() {
return config.getServletName();
}
public void init(ServletConfig config) throws ServletException {
this.config = config;
jspInit();
}
public void jspInit() {
_jspInit();
}
public void _jspInit() {
// Implemented by Web Container
}
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
_jspService(httpRequest, httpResponse);
}
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
// Implemented by Web Container
}
public void destroy() {
jspDestroy();
}
public void jspDestroy() {
// Implemented by Web Container
}
}
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.HttpJspPage;
public abstract class BasePage implements HttpJspPage {
private ServletConfig config;
public ServletConfig getServletConfig() {
return config;
}
public String getServletInfo() {
return config.getServletName();
}
public void init(ServletConfig config) throws ServletException {
this.config = config;
jspInit();
}
public void jspInit() {
_jspInit();
}
public void _jspInit() {
// Implemented by Web Container
}
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
_jspService(httpRequest, httpResponse);
}
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
// Implemented by Web Container
}
public void destroy() {
jspDestroy();
}
public void jspDestroy() {
// Implemented by Web Container
}
}
No comments:
Post a Comment