Beruflich Dokumente
Kultur Dokumente
Acknowledgements:
I would like to thank the following people: Charles Lyons for his book SCWCD Study Companion. Franck Allimant for his Java Documentation in HTMLHelp format. Frederic Esnault for his inspiring notes.
Contents
Chapter 3: Servlet Basics ..................................................................................................................................................... 3 Chapter 4: Servlet Contexts ................................................................................................................................................ 4 Chapter 5: Requests and Responses ................................................................................................................................... 6 Chapter 6: Request Dispatching and Wrappers ................................................................................................................ 11 Chapter 7: Filters .............................................................................................................................................................. 13 Chapter 8: Session Management ...................................................................................................................................... 14 Chapter 10: JSP basics ....................................................................................................................................................... 16 Chapter 15: Custom Tags .................................................................................................................................................. 18 Chapter 11: JSP Documents .............................................................................................................................................. 21 Chapter 12: EL ................................................................................................................................................................... 21 Chapter 13: Standard Actions and JavaBeans................................................................................................................... 21 Chapter 14: Tag libraries and JSTL .................................................................................................................................... 22 Chapter 16: Tag files ......................................................................................................................................................... 23 Chapter 9: Application Deployment ................................................................................................................................. 24 Chapter 18: Security.......................................................................................................................................................... 26 Chapter 17: Tag Deployment ............................................................................................................................................ 27 Chapter 20: Servlets 2.5 and JSP 2.1 Changes .................................................................................................................. 29
javax.servlet.Servlet public void init(ServletConfig config) throws ServletException public void service(ServletRequest req,ServletResponse res) throws ServletException, IOException public void destroy()
javax.servlet.GenericServlet public void init(ServletConfig config) throws ServletException public void init() throws ServletException public abstract void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
javax.servlet.http.HttpServlet protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
javax.servlet.ServletConfig public ServletContext getServletContext() public String getInitParameter(String name) public Enumeration getInitParameterNames() public String getServletName()
javax.servlet.GenericServlet public ServletConfig getServletConfig() public ServletContext getServletContext() public String getInitParameter(String name) public Enumeration getInitParameterNames() public String getServletName()
javax.servlet.ServletContextAttributeListener public void attributeAdded(ServletContextAttributeEvent scab) public void attributeRemoved(ServletContextAttributeEvent scab) public void attributeReplaced(ServletContextAttributeEvent scab)
javax.servlet.ServletRequest public Object getAttribute(String name) public Enumeration getAttributeNames() public void removeAttribute(String name) public void setAttribute(String name, Object o) public String getParameter(String name) public String[] getParameterValues(String name) public Enumeration getParameterNames() public Map getParameterMap() public ServletInputStream getInputStream() throws IOException Throws: IllegalStateException - if the getReader() method has already been called for this request IOException - if an input or output exception occurred public BufferedReader getReader() throws IOException Throws: IllegalStateException - if getInputStream() method has been called on this request IOException - if an input or output exception occurred public RequestDispatcher getRequestDispatcher(String path)
javax.servlet.http.HttpServletRequest public Enumeration getHeaders(String name) public String getHeader(String name) public Enumeration getHeaderNames() public int getIntHeader(String name) Throws: (unchecked) NumberFormatException - If the header value can't be converted to an int public long getDateHeader(String name) Throws: (unchecked) IllegalArgumentException - If the header value can't be converted to a date
public String getAuthType() public String getRemoteUser() public java.security.Principal getUserPrincipal() public boolean isUserInRole(String role) public javax.servlet.http.Cookie [] getCookies() public String getRequestedSessionId() public HttpSession getSession() public HttpSession getSession(boolean create) public boolean isRequestedSessionIdValid() public boolean isRequestedSessionIdFromCookie() public boolean isRequestedSessionIdFromURL()
javax.servlet.ServletResponse public ServletOutputStream getOutputStream() throws IOException Throws: IllegalStateException - if the getWriter method has been called on this response IOException - if an input or output exception occurred public PrintWriter getWriter() throws IOException Throws: UnsupportedEncodingException - if the character encoding returned by getCharacterEncoding cannot be used IllegalStateException - if the getOutputStream method has already been called for this response object IOException - if an input or output exception occurred public void flushBuffer() throws IOException public int getBufferSize() public boolean isCommitted() public void reset() Throws: IllegalStateException - if the response has already been committed public void resetBuffer() Throws: IllegalStateException - if the response has already been committed public void setBufferSize(int size) Throws: IllegalStateException - if this method is called after content has been written
public void setCharacterEncoding(String charset) public String getCharacterEncoding() public String getContentType() public void setContentType(String type) public Locale getLocale() public void setLocale(Locale loc) public void setContentLength(int len)
javax.servlet.http.HttpServletResponse public void addHeader(String name, String value) public void setHeader(String name, String value) public boolean containsHeader(String name) public void addIntHeader(String name, int value) public void setIntHeader(String name, int value) public void addDateHeader(String name, long date) public void setDateHeader(String name, long date) public void setStatus(int sc) public void sendError(int sc) throws IOException
Throws: IOException - If an input or output exception occurs IllegalStateException - If the response was committed before this method call public void sendError(int sc, String msg) throws IOException Throws: IOException - If an input or output exception occurs IllegalStateException - If the response was committed public void sendRedirect(String location) throws IOException Throws: IOException - If an input or output exception occurs IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL public String encodeURL(String url) public String encodeRedirectURL(String url) public void addCookie(Cookie cookie)
javax.servlet.ServletRequestAttributeListener public void attributeAdded(ServletRequestAttributeEvent srae) public void attributeRemoved(ServletRequestAttributeEvent srae) public void attributeReplaced(ServletRequestAttributeEvent srae)
javax.servlet.http.Cookie public Cookie(String name, String value) Throws: IllegalArgumentException - if the cookie name contains illegal characters (for example, a comma, space, or semicolon) or it is one of the tokens reserved for use by the cookie protocol public void setComment(String purpose) public String getComment() public void setDomain(String pattern) public String getDomain() public void setMaxAge(int expiry) public int getMaxAge() public void setPath(String uri) public String getPath() public void setSecure(boolean flag) public boolean getSecure() public String getName() public void setValue(String newValue) public String getValue() public int getVersion() public void setVersion(int v)
These attributes are not set if the requestDispatcher was obtained from getNamedDispatcher method. During forward, the following attributes are set on the request:
javax.servlet.forward.request_uri javax.servlet.forward.context_path javax.servlet.forward.servlet_path javax.servlet.forward.path_info javax.servlet.forward.query_string
These attributes always reflect the original request information, regardless if the container forwards or includes the request any further.
javax.servlet.ServletRequestWrapper public ServletRequestWrapper(ServletRequest request) Throws: IllegalArgumentException - if the request is null public ServletRequest getRequest() public void setRequest(ServletRequest request) Throws: IllegalArgumentException - if the request is null.
javax.servlet.ServletResponseWrapper public ServletResponseWrapper(ServletResponse response) Throws: IllegalArgumentException - if the response is null. public ServletResponse getResponse() public void setResponse(ServletResponse response) Throws: IllegalArgumentException - if the response is null.
Chapter 7: Filters
javax.servlet.Filter public void init(FilterConfig filterConfig) throws ServletException public void destroy() public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
javax.servlet.FilterChain public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException
javax.servlet.FilterConfig public String getFilterName() public ServletContext getServletContext() public String getInitParameter(String name) public Enumeration getInitParameterNames()
javax.servlet.http.HttpSessionAttributeListener public void attributeAdded(HttpSessionBindingEvent se) public void attributeRemoved(HttpSessionBindingEvent se) public void attributeReplaced(HttpSessionBindingEvent se)
javax.servlet.jsp.PageContext public abstract Exception getException() public abstract Object getPage() public abstract ServletRequest getRequest() public abstract ServletResponse getResponse() public abstract ServletConfig getServletConfig() public abstract ServletContext getServletContext() public abstract HttpSession getSession() public abstract void forward(String relativeUrlPath) throws ServletException, IOException public abstract void include(String relativeUrlPath) throws ServletException, IOException public abstract void include(String relativeUrlPath, boolean flush) throws ServletException, IOException public abstract void handlePageException(Exception e) throws ServletException, IOException public abstract void handlePageException(Throwable t) throws ServletException, IOException public ErrorData getErrorData()
javax.servlet.jsp.tagext.TagSupport The default behavior is: doStartTag() > SKIP_BODY, doAfterBody() > SKIP_BODY, doEndTag() > EVAL_PAGE
javax.servlet.jsp.tagext.BodyTag This interface provides a buffer to which all evaluated body content is written. Both of the following methods will be invoked when doStartTag() returns EVAL_BODY_BUFFERED and the body of the tag is not empty. public void doInitBody() throws JspException
javax.servlet.jsp.tagext.BodyContent public void clearBody() public void flush() throws IOException (always thrown) public JspWriter getEnclosingWriter() public abstract Reader getReader() public abstract String getString() public abstract void writeOut(Writer out) throws IOException
javax.servlet.jsp.tagext.BodyTagSupport Default return values: doStartTag() > EVAL_BODY_BUFFERED doAfterBody() > SKIP_BODY doEndTag() > EVAL_PAGE
javax.servlet.jsp.tagext.SimpleTag public void setJspContext(JspContext pc) public void setParent(JspTag parent) public JspTag getParent() public void setJspBody(JspFragment jspBody) public void doTag() throws JspException, IOException
javax.servlet.jsp.tagext.JspFragment public abstract void invoke(Writer out) throws JspException, IOException public abstract JspContext getJspContext() javax.servlet.jsp.tagext.DynamicAttributes
public void setDynamicAttribute(String uri, String localName, Object value) throws JspException
Chapter 12: EL
EL Functions <taglib> <function> <name></name> <function-class></function-class> <function-signature></function-signature> </function> </taglib>
class|beanName />
<jsp:setProperty name property value param> <jsp:getProperty name property /> <jsp:include page flush> <jsp:forward page /> <jsp:param name value >
JSTL
<c:out value escapeXml default /> <c:catch var> </c:catch> <c:set var value scope /> <c:set target property value/> <c:remove var scope /> <c:if test var scope /> <c:choose> <c:when test></c:when> <c:otherwise><c:otherwise> </c:choose> <c:forEach begin end step var></c:forEach> <c:forEach items></c:forEach> Methods during iterations: Object getCurrent() int getIndex() int getCount() boolean isFirst() boolean isLast() Integer getBegin() Integer getEnd() Integer getStep() <c:forTokens items delims var begin end step varStatus></c:forTokens> <c:url value context var scope />
<c:import url context varReader /> <c:redirect url context /> <c:param name value /> or <c:param name>value</c:param>
<servlet-mapping> <servlet-name></servlet-name> <url-pattern></url-pattern> </servlet-mapping> <session-config> <session-timeout></session-timeout> </session-config> <mime-mapping> <extension></extension> <mime-type></mime-type> </mime-mapping> <welcome-file-list> <welcome-file></welcome-file> </welcome-file-list> <error-page> <error-code></error-code> or <exception-type></exception-type> <location></location> </error-page> When the container forwards to an error page, it sets the following request-scoped attributes: javax.servlet.error.status_code javax.servlet.error.exception_type javax.servlet.error.message javax.servlet.error.exception javax.servlet.error.request_uri javax.servlet.error.servlet_name <jsp-config> <description></description> <display-name></display-name> <icon></icon> <taglib> <taglib-uri></taglib-uri> <taglib-location></taglib-location> </taglib> <jsp-property-group> <description></description> <display-name></display-name> <icon></icon> <url-pattern></url-pattern> <el-ignored></el-ignored> <page-encoding></page-encoding> <scripting-invalid></scripting-invalid> <is-xml></is-xml> <include-prelude></include-prelude> <include-coda></include-coda> </jsp-property-group> </jsp-config>
<variable> <description></description> <name-given></name-given> or <name-from-attribute></name-from-attribute> <variable-class></variable-class> <declare></declare> <scope></scope> </variable> <attribute> <description></description> <name></name> <required></required> <fragment></fragment> or <rtexprvalue></rtexprvalue><type></type> </attribute> <tag-file> <description></description> <display-name></display-name> <icon></icon> <name></name> <path></path> <example></example> <tag-extension></tag-extension> </tag-file> <function> <description></description> <display-name></display-name> <icon></icon> <name></name> <function-class></function-class> <function-signature></function-signature> <example></example> <function-extension> <extension-element></extension-element> </function-extension> </function>
@Resource(name=, type=) This is equivalent to declaring <resource-ref> in the deployment descriptor. @Resources({@Resource(name=, type=), @Resource(name=, type=)}) @PostContruct @PreDestroy @EJB replaces <ejb-ref> and <ejb-local-ref> @WebServiceRef replaces <resource-ref>