Sunday, 28 September 2014

What are different JSP scriptlets ?

JSP provides different scriptlets to use java code in JSP.

1.Directives Tag

<%@ %>
-------------

This tag is used to include external content in our jsp

this tag has mainly three attributes

1.Page
2.taglib
3.include

<%@ taglib uri="relative UR""  prefix=""%>

when we have predefined,custom tags, we can include them in our JSP and use them with prefix.

<%@ page import="relaive url" %>

this works similar to import statement in Java.

<%@ include file="relative url"%>

include attribute can be used  to include external js,jsp and css files

file will  be included in our file during the translation phase.

II. Declarative tag
-----------------------
<%! %>
This tag is used to declare variables in JSP

<%! int a;%>

III. Expression tag
--------------------------

This tag is used to write any expressions which result in string.

<%=Expression%>

we should not use semicolon at the end of the expression


IV. JSP comments
-----------------------

<% -- comments---%>

used to write comments in JSP

What do you know about JSP life Cycle?

Hey Guys.... here I will try to explain basic details of JSP which might be useful for the people who are beginners.

JSP :JSP stands for JAva Server Pages.

Most of you know might know about HTML which is used to display static content.Using JSP we can write pages which displays dynamic content to the user based on server response.

Main advantage of JSP is it is built on Servlet API so it has acess to all Java API like JDBC,JNDI,JAXP.

Let me explain lifeCycle of JSP:

JSP life cycle has below three steps:

1.Initilisation
2.Execution
3.CleanUp

Initilisation :

jspInit() method is executed during phase. this method will execute when JSP is loaded into memory.

once JSP is loaded, JSP container converts it to servlet and compiles it.

Then JSP container passes request to servlet container. Servlet container then executes the servlet which sends the response to client

Execution Phase 

:During this phase, jsp will process all requests from users and sends the response.

_jspService(HttpServletRequesst,HttpServletResponse) method is used to process all user requests.

This method will be executed once for each request.

CleanUP :

during this phase,the resources which are allocated during initilisation phase are cleaned.
jspDestroy( ) method will be executed during this phase.
 

Search This Blog