Ishikawa Yoshi
Ishikawa Yoshi

Reputation: 1779

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

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.

Upvotes: 3

Views: 941

Answers (3)

quando
quando

Reputation: 49

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

<% %> Tag is write Statement in JSP page

JSP look like a java class

over!

Upvotes: 1

Manish Nagar
Manish Nagar

Reputation: 1046

Scriptlets are blocks of code delimited by <% and %>

Declarations are delimited by <%! and %>

you can refer this link it http://inside.mines.edu/~crader/cs443/Chapters/Chap10.html

Upvotes: 0

RoryB
RoryB

Reputation: 1047

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

Upvotes: 7

Related Questions