" VS "<% = ...%>" While working with JSP files and servlets, I came across <% … %> and <%= … %> . W...">

JSP - what's the difference between "<% ...%>" VS "<% = ...%>"

While working with JSP files and servlets, I came across <% … %> and <%= … %> .

What is the difference between both cases?

thanks

+4
source share
3 answers

<%= … %> will call a variable, where <% … %> denotes a script or some code that is executing.

Here are links to jsp documentation:

+10
source
 <%= new java.util.Date() %> 

coincides with

 <% out.println(new java.util.Date()) %> 

There are three types of scripts:

  • Form script expressions <% = expression%> that are evaluated and inserted into the output file
  • Script of the form <% code%> that is inserted into the servlet service method
  • Script form declarations <%! code%> , which are inserted into the body of the servlet class outside of any existing methods. For example:

     <%! public int sum(int a, int b) { return a + b; } %> 
+8
source

In the case of <% ... %> you add the code on the server side. And in the case of <%= ... %> you add code on the server side, which automatically prints something. It can be seen as a shortcut to <% out.print( something ) %> .

+5
source

All Articles