
- page directive
- include directive
- taglib directive
Syntax of Directive :
<%@ directive attribute="value" %>
JSP page directive:
Attributes that performed to an entire JSP page.
Syntax :
<%@ page attribute="value" %>
Attributes of JSP page directive
- import
- contentType
- extends
- info
- buffer
- language
- isELIgnored
- isThreadSafe
- autoFlush
- session
- pageEncoding
- errorPage
- isErrorPage
JAVA Tutorial Video
[embed]https://www.youtube.com/watch?v=UbpbqqIw_3Q[/embed]4)info :This property just sets the data of the JSP page which is recovered later by utilizing getServletInfo() strategy for Servlet interface.Case of information trait :<%@ page info="composed by Sonoo Jaiswal" %>Today is: <%= new java.util.Date() %>The web compartment will make a strategy getServletInfo() in the subsequent servlet.For illustration:open String getServletInfo() {return "created by Sonoo Jaiswal";} 5)buffer :The cradle trait sets the support measure in kilobytes to deal with yield created by the JSP page.The default size of the cushion is 8Kb.Case of cushion quality :<%@ page buffer="16kb" %>Today is: <%= new java.util.Date() %>6)language The dialect characteristic indicates the scripting dialect utilized as a part of the JSP page. The default esteem is "java".7)isELIgnored We can disregard the Expression Language (EL) in jsp by the isELIgnored quality. As a matter of course its esteem is false i.e. Articulation Language is empowered as a matter of course. We see Expression Language later.<%@ page isELIgnored="true" %>8)isThreadSafeServlet and JSP both are multi threaded. If you need to control this conduct of JSP page, you can utilize is ThreadSafe property of page directive. The estimation of is ThreadSafe esteem is true. If you make it false, the web holder will serialize the various solicitations, i.e. it will hold up until the JSP gets done with reacting to a demand before passing another demand to it. If you make the estimation of is ThreadSafe quality like
<%@ page isThreadSafe="false" %>
The web compartment in such a case, will create the servlet as:open class SimplePage_jsp expands HttpJspBaseactualizes SingleThreadModel{}9)errorPage :The errorPage credit is utilized to characterize the blunder page, if special case happens in the present page, it will be diverted to the mistake page.Case of errorPage characteristic :/index.jsp<%@ page errorPage="myerrorpage.jsp" %><%= 100/0 %>10)isErrorPage The isErrorPage credit is utilized to proclaim that the present page is the blunder page. Example:/myerrorpage.jsp<%@ page isErrorPage="true" %>Sorry an exception occured!The exception is: <%= exception %>Jsp Include Directive:
The incorporate mandate is utilized to incorporate the substance of any asset it might be jsp record, html document or content document. The incorporate mandate incorporates the first substance of the included asset at page interpretation time (the jsp page is deciphered just once so it will be ideal to incorporate static asset).
Syntax
<%@ include file="resourceName" %> Example:<%@ include file="header.html" %>Today is: <%= java.util.Calendar.getInstance().getTime() %>JSP Taglib directive
The JSP taglib order is utilized to characterize a label library that characterizes many labels. We utilize the TLD (Tag Library Descriptor) record to characterize the labels. In the custom label segment we will utilize this label so it will be ideal to learn it in custom tag.
Syntax
- <%@ taglib uri="uriofthetaglibrary"prefix="prefixoftaglibrary" %>
Exception Handling:
The special case is regularly a protest that is tossed at runtime. Special case Handling is the procedure to deal with the runtime mistakes. There may happen special case whenever in your web application. So dealing with special cases is a more secure side for the web engineer. In JSP, there are two approaches to perform exemption taking care of
- By errorPageand isErrorPage attributes of page directive
- By
element in web.xml file.
- index.jsp for input values
- process.jsp for dividing the two numbers and displaying the result
- error.jsp for handling the exception
index.jsp
process.jsp
<%@ page errorPage="error.jsp" %><%String num1=request.getParameter("n1");String num2=request.getParameter("n2");int a=Integer.parseInt(num1);int b=Integer.parseInt(num2);int c=a/b;out.print("division of numbers is: "+c);%>error.jsp
<%@ page isErrorPage="true" %>Sorry an exception occured!
Exception is: <%= exception %>Error-page element in web.xml file
This approach is better since you don't have to determine the errorPage quality in each jsp page. Determining the single section in the web.xml record will deal with the special case. For this situation, either indicate special case sort or blunder code with the area component. In the event that you need to deal with all the exemption, you should determine the java.lang.Exception in the special case sort component.
web.xml file if you want to handle any exception