JSP(全称Jakarta Server Pages,曾称为JavaServer Pages)是由昇陽電腦公司主导建立的一种动态网页技术标准。JSP部署于网络服务器上,可以响应客户端发送的请求,并根据请求内容动态地生成HTML、XML或其他格式文档的Web网页,然后返回给请求者。JSP技术以Java语言作为脚本语言,为用户的HTTP请求提供服务,并能与服务器上的其它Java程序共同处理复杂的业务需求。
publicclassMyActionTagextendsTagSupport{//Releases all instance variables.publicvoidrelease(){...}publicMyActionTag(){...}//called for the start tagpublicintdoStartTag(){...}//called at the end tag}
<%@ page errorPage="myerror.jsp" %>
<%@ page import="com.foo.bar" %>
<html><head><%! int serverInstanceVariable = 1;%>
...
<% int localStackBasedVariable = 1; %>
<table><tr><td><%= "expanded inline data " + 1 %></td></tr>
...
最后生成的JAVA SERVLET
packagejsp_servlet;importjava.util.*;importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;importjavax.servlet.jsp.*;importjavax.servlet.jsp.tagext.*;importcom.foo.bar;//imported as a result of <%@ page import="com.foo.bar" %>import...class_myserlvetimplementsjavax.servlet.Servlet,javax.servlet.jsp.HttpJspPage{//inserted as a//result of <%! int serverInstanceVariable = 1;%>intserverInstanceVariable=1;...publicvoid_jspService(javax.servlet.http.HttpServletRequestrequest,javax.servlet.http.HttpServletResponseresponse)throwsjavax.servlet.ServletException,java.io.IOException{javax.servlet.ServletConfigconfig=...;//get the servlet configObjectpage=this;PageContextpageContext=...;//get the page context for this requestjavax.servlet.jsp.JspWriterout=pageContext.getOut();HttpSessionsession=request.getSession(true);try{out.print("<html>\r\n");out.print("<head>\r\n");...//from <% int localStackBasedVariable = 1; %>intlocalStackBasedVariable=1;...out.print("<table>\r\n");out.print(" <tr><td>");//note, toStringOrBlank() converts the expression into a string or if// the expression is null, it uses the empty string.//from <%= "expanded inline data " + 1 %>out.print(toStringOrBlank("expanded inline data "+1));out.print(" </td></tr>\r\n");...}catch(Exception_exception){//clean up and redirect to error page in <%@ page errorPage="myerror.jsp" %>}}}