开发者

what is the difference between servlet and JSP? Please describe <% expr %> and <%! expr %> tags of JSP, when and where they get executed? [duplicate]

This question already has answers here: 开发者_开发百科 Closed 12 years ago.

Possible Duplicates:

What is the difference between <% … %> and <%! … %> in jsp

When do you use a JSP and when a Servlet?

what is the difference between servlet and JSP? Please describe <% expr %> and <%! expr %> tags of JSP, when and where they get executed?


A Servlet is a Java class which conforms to the Java Servlet API, a protocol by which a Java class may respond to http requests.

A JSP or java server page is essentially a servlet that allows one to easily mix page logic with markup (html, xml, etc.) and write. JSPs get compiled into servlets which are then executed for http requests

The <%!..%> is used to add declarations in jsp pages

The <% %> code goes into the service method of the compiled JSP (which is a servlet) and is executed there.

More on Declarations and SCriptlets


First part is as rightly answered by naikus. The other part of answer is as follows :

<% ... %> is used to embed some java code within the main service() method of the JSP. It is executed during the rendering of the page.

<%! ... %> is used to define code outside of the flow of the page, and therefore outside the main service() method. Typically, this was used to define utility methods that would be called from within a <% ... %> block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜