JSP

JSP – Introduction

Servlet JSP Servlets run faster than JSP. JSP runs slower than servlet as it takes time to compile the program and convert into servlets. It is hard to write code in servlet. It’s easier to code in JSP compared to servlets. In MVC architecture, servlet works as a controller. In MVC architecture, JSP works as …

JSP – Introduction Read More »

JSP – Scriptlet Tags

JSP Scriptlet Tag Syntax: <%  java code %> Note: Variable and methods declare in scriplet tag are not of class level declaration. welcome.jsp: <html>            <head>                        <title>Scriplet tag example</title>            </head>            <body>                        <%                                    out.println(“Sum of 10 and 20 = “);                                    out.print(10 + 20);                        %>            </body></html>

JSP – Declaration Tags

JSP Declaration Tag Syntax: <%!  Variable or method Declaration %> welcome.jsp: <html>            <head>                        <title>Declaration tag example</title>            </head>             <body>                        <%!                                    int sum(int a, int b)                                    {                                                return a + b;                                    }                        %>                         <%                                    out.println(“Sum of 10 and 20 = ” + sum(10, 20));                        %>            </body></html>

JSP – Expression Tags

JSP Expression Tag Syntax: <%=  expression %>  welcome.jsp: <html>            <head>                        <title>Expression tag example</title>            </head>            <body>                        Sum of 10 and 20 = <%= 10+20 %>            </body></html>

JSP – Comment Tag

JSP Comment Tag Syntax: <%– JSP comment –%> welcome.jsp: <html>            <head>                        <title>Comment tag example</title>            </head>            <body>                        This Line is Visible.                        Comment Line followed by this not visible.                        <!– Hello World –>            </body></html>

JSP Directives

JSP Directives: JSP directives provides the instructions and directions to the web container about how to control the processing JSP page. Syntax: <%@ directiveName attributeName=”attributValue” %> Types of JSP directives: Import Attribute Of JSP Page Directive This attribute is used to import interface, classes or whole package. You can import more than one package separated …

JSP Directives Read More »

JSP – Session Page Directive

Session Attribute Of JSP Page Directive This attribute checks whether JSP page is in a particular HTTP session or not. It can have true or false value. Default value is true. Syntax: <%@ page session=”value”%> welcome.jsp: <%@ page session=”true” %><html>            <head>                        <title>session page directive example</title>            </head>            <body>                        <h2>In JSP Session automatically created</h2>                        <h2>Every session has …

JSP – Session Page Directive Read More »

JSP – ErrorPage Directive

errorPage attribute: Syntax: <%@ page errorPage=”value”%> welcome.jsp: <%@ page errorPage=”errorPage.jsp” %><html>            <head>                        <title>isErrorPage and errorPage page directive example</title>            </head>            <body>                        <%= 0/0 %>            </body></html> errorPage.jsp: <%@ page isErrorPage=”true” %><html>            <head>                        <title>errorPage page directive example</title>            </head>            <body>                        <h3>Some exception occurred.</h3>                        Exception: <%=exception %>            </body></html>

JSP – Include Directive

JSP Include Directive Syntax: <%@ include file=”Relative URL” %> welcome.jsp: <html>            <head>                        <title>include directive example</title>            </head>            <body>                        <h3>Hello this is an include directive example.</h3>                        <%@ include file=”hello.jsp” %>            </body></html> hello.jsp: <html>            <head>                        <title>Hello</title>            </head>            <body>                        <h3>This content is of “hello.jsp” file.</h3>            </body></html>

JSP – Implicit Objects – out

JSP implicit objects are 9 and given below: JSP Out Implicit Object welcome.jsp: <html>            <head>                        <title>out implicit object example</title>            </head>            <body>                        <%                                    out.print(“We can display message using out”);                        %>            </body></html>

Scroll to Top