13. JSP
13. JSP
----------------
JSP
---
- JSP is used to develop server side dynamic web applications like Servlets
Servlets vs JSP
---------------
- JSP code is less than Servlet as in JSP we can use JSP tags,
--------------
- jspInit()
- _jspService()
- cannot be overridden
- jspDestroy()
JSP Tags
--------
- Directive tags
- Scriptlet tags
- Action tags
- <jsp:include>
- <jsp:forward>
- <jsp:param>
- <jsp:useBean>
- <jsp:setProperty>
- <jsp:getProperty>
Ex:
or
---------------------
Ex:
....
Refer programs
- header.jsp
- footer.jsp
- includedemo.jsp (run)
Scriptlet tags
--------------
Declaration tag
---------------
Ex:
...
%>
...
%>
Expression tag
--------------
Ex:
Script tag
----------
Ex:
<%
for(int i=1;i<=10;i++)
out.println(i);
%>
Create a JSP file which reads the number from HTML file and displays
Refer programs
- fact.html (run)
- Factorial.jsp
Refer programs
- color.html(run)
- BGColor.jsp
Note
----
----------------
JSP Tags
--------
- page directive tag => <%@page ... %> => used to import java packages
- include directive tag => <%@include ... %> => used to include other JSP files
- Declaration tag => <%! ... %> => used to declare variables and to define methods
- Expression tag => <%= ... %> => used to access the value of variable and to call methods
- Script tag => <% ... %> => used to include Java statements
---------------
- <jsp:include>
- <jsp:forward>
- <jsp:param>
- <jsp:useBean>
- <jsp:setProperty>
- <jsp:getProperty>
<jsp:include> and <jsp:forward>
-------------------------------
Refer programs
- First.jsp (run)
- Second.jsp
- Third.jsp
<jsp:param>
-----------
used to send the parameters from one JSP page to another JSP page
Refer programs
- JspParam1.jsp (run)
- JspParam2.jsp
----------------------
JavaBean
--------
A JavaBean is a public class with private properties and public
Ex:
this.bno = bno;
return bno;
...
...
-------------------
------------------------------
Right click on Book.java -> Source -> Generate Getters and Setters
JSTL
----
- In order to use JSTL tags we need to copy "jstl1.2.jar" into WEB-INF/lib folder
Refer programs
- JSTLCore1.jsp
- JSTLCore2.jsp
- JSTLCore3.jsp
- JSTLCore4.jsp
----------------
database table
Web Services - 2
Spring - 6
Microservices - 2
Angular - 3
Note
----
No classes on Monday and Tuesday i.e., 16/Jan and 17/Jan @7PM (IST)