Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What difference between <%%> and <%!%>

Tags:

jsp

jsp-tags

I try to find that in JSP people use several different tags like <% %> and<%! %> when add Java code to page, but can anyone tell me what is the main difference between this two tags.

Thanks.

like image 751
Ishikawa Yoshi Avatar asked Apr 12 '26 10:04

Ishikawa Yoshi


2 Answers

So, there are a number of different jsp scripting elements, each with different usages. These are:

  • <% %>: Scriptlets
    • Evaluates a Java expression. Does not display any result in the HTML produced. Variables declared have only local scope, so cannot be accessed from elsewhere in the .jsp
  • <%! %> : Declarations
    • Allows the declaration of methods or variables, which can then be accessed elsewhere in the .jsp
  • <%@ %>: Directives
    • Specifies page-dependent attributes, such as the scripting language used, or "include" statements
  • <%= %>: Expressions
    • Evaluates a Java expression. Inserts the result (as a string) into the HTML in the .jsp
  • <%-- --%>: Comments
    • JSP comment tags. These will not show up in the page source, unlike HTML comments

For full documentation, see: http://docs.oracle.com/cd/B14099_19/web.1012/b14014/genlovw.htm

like image 106
RoryB Avatar answered Apr 15 '26 00:04

RoryB


<!% %> Tag is declare java method(function) in JSP page

<% %> Tag is write Statement in JSP page

JSP look like a java class

over!

like image 30
quando Avatar answered Apr 14 '26 23:04

quando



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!