CuriousMind
CuriousMind

Reputation: 8943

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?

Upvotes: -3

Views: 653

Answers (2)

Serge Ballesta
Serge Ballesta

Reputation: 149145

  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.

Upvotes: 1

gsl
gsl

Reputation: 676

1) it's dynamic if it contains any JSP elements, like code snippets, JSP tags etc. If it contains only HTML, then it's pretty static, although if it is processed as a JSP, then the constant response is computed dynamically on each call (safe Caching).

2) yeah much like that. Actually the static text of the JSP goes into out.write() Statements in a Java class; the whole JSP is transpiled to a Java class.

3) funny question. It's all a question of Interpretation. If you name it .jsp or have your web container process it as JSP in some other ways (depends), then you may call it a JSP.

4) this question is not quite clear. The snippets are executed after the static text has been output up to this point.

Upvotes: 1

Related Questions