How JSP work

jsp

Syntax

scriptlet

<% int count=0; out.println("This is a scriptlet"); %>

This block is placed in the body of method _jspService(request, response)

derective

<%@ page import="java.util.*,java.xml.*" %>
<%@ include file="xxx" %>
<%@ taglib tagdir="/WEB-INF/tags/xxx" prefix="xxx" %>

expression

<%= "This is a expression argument" %>

declaration

<%! int count=0 %>
<%! int doubleCount() { count = count*2; return count; } %>

This is equivlant with the member field and member method of the generated servlet.

comment

<!-- HTML Comments -->
<%-- JSP Comments --%>

The first is called _output comments_, while the second is called hidden comments.

implicit Objects in scriptlets and expressions

about the generated servlet

it’s a subclass of HttpJspPage, which inherited JspPage

In JSP, you can get its reference by a implicit object named page.

jsppage

The methods of JspPage:

jspInit()
jspDestroy()

The methods of HttpJspPage

_jspService()

You can override the jspInit() and jspDestroy() methods, but not for _jspService() method.

about the PageContext

PageContext is a subclass of JspContext. jspContextpageContext

about the configuration

1. config jsp for global in deployment descriptor

<web-app ...>

...

<jsp-config>

<jsp-property-group>

<url-pattern>*.jsp</url-pattern>

<el-ignored>true</el-ignored>

<scripting-invalid>true</scripting-invalid>

</jsp-property-group>

...

</web-app>

2. config jsp in the page directive

<%@ page isELIgnored="true" isScriptingEnabled="false" .... %>