Class Template


  • public abstract class Template
    extends Object
    • Field Detail

      • request

        protected javax.servlet.http.HttpServletRequest request
      • response

        protected javax.servlet.http.HttpServletResponse response
      • pageContext

        protected javax.servlet.jsp.PageContext pageContext
      • session

        protected javax.servlet.http.HttpSession session
      • application

        protected javax.servlet.ServletContext application
      • out

        protected javax.servlet.jsp.JspWriter out
      • config

        protected javax.servlet.ServletConfig config
    • Constructor Detail

      • Template

        public Template​(javax.servlet.jsp.PageContext pc)
    • Method Detail

      • render

        public abstract void render()
                             throws Exception
        This is the method that template must implement.
        Throws:
        Exception - Java-islands threw an exception.
      • redirect

        protected void redirect​(String location)
                         throws IOException
        Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root. If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to. After redirect, template execution continues. There will be no more output to the response, but maybe there are other effects. In order to avoid it, you can follow it by if(true) return; Uses status code 302.
        Parameters:
        location - the redirect location URL, can be relative
        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
      • forward

        protected void forward​(String u)
                        throws javax.servlet.ServletException,
                               IOException
        Forward. After forward, template execution continues. There will be no more output to the response, but maybe there are other effects. In order to avoid it, you can follow it by if(true) return;
        Parameters:
        u - the forward location URL, can be relative
        Throws:
        javax.servlet.ServletException - if the target resource throws this exception
        IOException - if the target resource throws this exception
        IllegalStateException - If the response was committed or if a partial URL is given and cannot be converted into a valid URL
      • quote

        protected final String quote​(Object o)
        Quotes a value so that it can be an attribute's value. Escapes " by " and encloses in ". For null returns quote(""). Called from generated write().
        Parameters:
        o - object
        Returns:
        quoted
      • unquote

        protected final String unquote​(Object o)
        Escapes " by " . For null returns "". Called from generated write().
        Parameters:
        o - Object
        Returns:
        ...
      • escape

        protected final String escape​(Object o)
        escape for html: ≤ & Called from generated write().
        Parameters:
        o - Object
        Returns:
        escaped
      • escape

        protected final String escape​(int i)
        Escapes an int for html: just convert it to String. Called from generated write().
        Parameters:
        i - int
        Returns:
        escaped
      • attribute

        protected final void attribute​(String key,
                                       boolean b)
                                throws IOException
        Boolean attribute: write the key if the value is true. Called from generated write().
        Parameters:
        key - key
        b - value
        Throws:
        IOException - couldn't write
      • attribute

        protected final void attribute​(String key,
                                       Object v)
                                throws IOException
        Attribute: If the value is empty, writes just the key, otherwise key and value, quoted.
        Parameters:
        key - key
        v - value
        Throws:
        IOException - bad IO
      • write

        public final Template write​(int i)
                             throws IOException
        Writes an int to out. Called from generated write().
        Parameters:
        i - ...
        Returns:
        same template
        Throws:
        IOException - ...
      • write

        public final Template write​(Object o)
                             throws IOException
        Writes an object to out. Does nothing if the object is empty (null or its toString() is null or "").
        Parameters:
        o - ...
        Returns:
        same template
        Throws:
        IOException - ...
      • write

        public final Template write​(String s)
                             throws IOException
        Writes a String to out. Does nothing if the String is null or "".
        Parameters:
        s - ...
        Returns:
        same template
        Throws:
        IOException - ...