Saturday, 9 March 2013

JSP ELEMENTS WITH EXAMPLE

jsp elements
               Hello friends In my previous post i explained introduction of advanced java.Today i am going to explain you JSP ELEMENTS.In this post i will explain how to use jsp elements in programming with example.
               In general jsp elements has three types which are as follows.
1:-DIRECTIVE
2:-SCRIPTING
3:-STANDARD ACTION
1:-DIRECTIVE
Let us start with Directive.Directives is a jsp element which is provide globle information for the transletion phase.Directives can not contain business logic.It also contains three sub fields.
1:-PAGE
2:-INCLUDE
3:-TAGLIB
PAGE DIRECTIVE
        It provides page specific properties which are required for processing a java server page.
for example   <%@page import="java..utill.*"%>,<%@page session="false"%>,<%@page content type="text/html"%>.This is is page directives with examples.
INCLUDE DIRECTIVE
        During the translation time of the jsp page Include directive tells the container to add the defined resource content to the java server page.Here resource must be a url which is accessible by the container.For example
<%@include file="header.html"%>
TAG LIBRARY
      It is used for define the tag library Which contains collection of tags.We can define the custom tags as well as standard tags in Tag library.
example:<%@ taglib uri="/WEB-INF/A.TLD" prefix="c"%>
this example shows that we can use custom tags which are stored in A.tld file.
2:-SCRIPTING :-
         For insert a java code into jsp page Scripting elements are used.there are three scripting elements are used which are as follows
1:DECLARATIONS
2:SCRIPTLETS
3:EXPRESSIONS
   Let us start with declarations.
1:Declarations:-It is used to define any number of methods or variable which are going to be used in scriptlets or expressions.
example  <%! int i=1;%>
2:Scriptlets:-these statements are used to provide a business logic in jsp page.Syntex of Scriptlets are as follows.<% java statements %>
3:Expressions:-These are used to output the value of java expressions to the implicit object known as out.
syntex:-<%=java expressions%>
3:-STANDARD ACTION:
1:<jsp:useBean>
      It provides an instance of java bean class which is available for use in jsp page.
e.g.<jsp:useBean id="fn" class="classname">
2:-<jsp:setProperty>
      It is used to set property of java bean object.
e.g.<jsp:setProperty name="bean_name" property="*" propertyName="paramName" value=<%=expression%>
3:-<jsp:getProperty>
     It is used to access defined property of java bean.
e.g.<jsp:getProperty name="bean_name" property="*" propertyName="property_Name" %>
So these are the Standard action which are used in jsp elements.there are another standard action are also available which are<jsp:param>,<jsp:include>,<jsp:forword>
 

No comments:

Post a Comment