javajspservletsweb-container

Does JSP provide the dynamic behaviour to a web-page?


Although I know JSP (basic understanding), I have some doubts on the JSP technology.

Consider the below simple jsp:

<html>
    <head>
        <title> This is demo</title>
    </head>
    <body>
        <h1> The current time is <%=new java.util.Date()%> </h1>
    </body>
</html>

With respect to this, I have some doubts (which I have been keeping at the back of my mind):

1) The basic text of this jsp is same, is it dynamic page because it has JAVA code in it?

2) When a user accesses this jsp page, does the container first execute the java code and replaces the output of java code inside the page?

3) What makes this a jsp page? Do mixing of html and java code make it a jsp?

4) Can the java code (within <% %> ) live independent of html? or they are coupled (the java code has to be present in html page).

They might be basic questions, can anyone help me in understanding them?


Solution

    1. Yes it is dynamic because it is computed (even partially) at run time - here the java scriptlet is the dynamic part
    2. Not exactly. JSP is not a template engine. JSP pages are fully translated to java source and then compiled to class files by the servlet container. Then those classes are executed at run time.
    3. the extension .JSP makes it a JSP file. Then it must respect the JSP syntax to be correctly processed by a servlet container.
    4. Reverse the question. Java code normally lies in java source files. A Java class implementing the HttpServlet interface can be directly map to an URL by the servlet container. And Java code can lie in a scriptlet in a JSP

    But as you were said in comment, you really should read documentation on that before asking questions here.