이 글은 Head First Servlet and JSP 책을 참고하여 작성하였습니다.
서블릿과 JSP에 무슨 관계가.. 있습니다!
Container가 jsp파일을
.java
소스 파일로 translate한다.
여기서 JSP syntax error가 잡힘.
.class
로 컴파일한다.여기서 java language/syntax error가 잡힘.
jspInit()
method를 실행._jspService()
method를 호출해서 쓰레드 만들고 클라이언트의 요청 처리.<html><body>
<%! int count=0; %>
The page count is now:
<%= ++count %>
</body></html>
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class BasicCounter_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
int count = 0;
private static java.util.Vector _jspx_dependants;
public java.util.List getDependants() {
return _jspx_dependants;
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;
try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType(“text/html”);
pageContext = _jspxFactory.getPageContext(this, request,
response, null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write(“\r<html>\r<body>\r”);
out.write(“\rThe page count is now: \r”);
out.print( ++count );
out.write(“\r</body>\r</html>\r”);
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (_jspx_page_context != null)
_jspx_page_context.handlePageException(t);
}
} finally {
if (_jspxFactory != null)
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
<web-app ...>
<servlet>
<servlet-name>blabla</servlet-name>
<jsp-file>/TestInit.jsp</jsp-file> ->요거.
</servlet>
<servlet-mapping>
<servlet-name>blabla</servlet-name>
<url-pattern>/blablaTest.jsp</url-attern>
</servlet-mapping>
</web-app>
<% %>
<%@ %>
<%= %>
EL
Please contact: ${applicationScope.mail}
일반 표현
Please contact: <%= application.getAttribute("mail") %>