-3

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?

CuriousMind
  • 8,301
  • 22
  • 65
  • 134
  • 1
    Asking one question per Question is easier answering and/or finding duplicates. – BalusC Aug 09 '16 at 13:04
  • 1
    Why not just read any JSP tutorial? I mean, you say you know JSP, but it sounds like you don't know what it *is*, which I find odd. – Dave Newton Aug 09 '16 at 13:04
  • Thanks for your inputs, I am of opine they are related questions, that is why asked these four questions. I did read some JSP tutorial, but I didn't get answers to my question, hence asking here. – CuriousMind Aug 09 '16 at 13:06

2 Answers2

1

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.

gsl
  • 676
  • 5
  • 16
1
  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.

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
  • Thanks for your reply. Going by this, if we have Javascript code in jsp file, it would eventually be put inside the out.write() in java file which container generates. And when the page reaches to web-browser, the javascript engine of browser would execute it. I hope it is correct. – CuriousMind Aug 09 '16 at 15:16