View RSS Feed


Java Server Pages (JSP) tutorials and examples.

  1. Is JSP variable declaration thread safe?

    , 01-01-2012 at 07:20 PM
    No, in JSP the variable declaration is not at all thread safe as the declared variables are ended up as instance variable in generated servlet not in body of _jspservice() method.

    The given declaration is not considered to be thread safe: as they are declarations and are evaluated only one time when page gets loaded.

    <%!int a=5;%>

    The given declaration is considered thread safe: as in the scriplets the variables that have been declared are not shared ...
  2. Hidden and Output Comments

    , 01-01-2012 at 07:00 PM
    An output comment is sent to the client where it becomes viewable in the source of browser.

    <!-- This is a comment which is sent to client -->

    JSP page is documented by hidden comment however it is not sent to client. Hidden comment is ignored by the JSP engine and no code is processed in tags of the hidden comments.

    <%-- This comment will not be visible to client --%>

    Updated 01-15-2012 at 08:43 AM by JSP

  3. Life cycle methods of a JSP

    , 01-01-2012 at 06:47 PM
    • Pre-translated: Before the JSP file is compiled or translated, into the Servlet.
    • Translated: The JSP file is being compiled & translated as a Servlet.
    • Initialized: Before handling requests of service method, the container calls the jspInit() to do the initialization of the Servlet. Called just one time per Servlet instance.
    • Servicing: client requests are served. For each request, container calls it.
    • Out of service: The Servlet instances are out of their services. The container calls
  4. What is JSP?

    , 01-01-2012 at 06:45 PM
    Java Servlet technology’s extension is Java ServerPages. JSP is used as presentation layer to combine the Java code and HTML. Java Servlet technology generates HTML along with out.println(“<html>….. </html>”) statements (out is PrintWriter). Embedding HTML code to the escape characters is a process which is hardly maintained and is cumbersome. A level of abstraction is provided by the JSP technology in order to enable a developer to use the action elements and custom tags. This makes ...