USING BEANS IN JSP PAGES Page scope Request scope Session scope Application scope
JSP COMPONENTS < jsp:use bean> < jsp:set property> < jsp.useBean >tag < jsp.property >tag < jsp:get property>read the values of class property
USING COOKIES AND SESSION FOR SESSION TRACKING Persistent cookies Session cookies
STRUCTURE OF COOKIES
3 steps Creating cookies object Set maximum age http response
session Particular interval of time Stored in server Four types of technique used in sessions tracking Cookies Hidden form field url rewriting http session object
CONNECTING TO DATABASE IN JSP The database is used for for storing various types of data It has huge storing capacity in giga bytes We have to install 3 software In order to connect our database 1.Tomcat webserver 2.mysql server 3.JDK
Jsp with database 2 steps Step 1 Create database open mysql server command mysql >CREATE DATABASE students; Open mysql >with command Mysql > CREATE TABLE students table( rollno INT(4) NOT NULL AUTO_INCREMENT)
Name VARCHAR(50)NOT NULL; Address VAR CHAR(50)NOT NULL; Phone no VARCHAR(15)NOT NULL; PRIMARY KEY(ROLL _NO)
STUDENT DATABASE STUDENTS TABLE NAME ADDRESS PHONE NO ROLLNO
STEP-2 ESTABLISING CONNECTION BETWEEN Jdbc driver HTTP\\WWW.mysql.com Open jdbc connector mysql_connection_java_xx.bin.jar C:your_tomcat_directory/common/lib <copy and paste Contrl pannel >system properties >environmental variable Variable & set classpath
Demonstrate the usage of page and include directives Main.jsp <!DOCTYPE Html> <html> <head> <meta charset=“UTF-8”> <title>main page</title> </head> <body> <h1>main page<h1> <p>This is main page content.</p> <%---including the header.jsp using include directive----%> <%@ include file =“ header.jsp ”%>
EXPRESSION LANGUAGE(EL) <P>Number of items in the session :${ Expression.itemcount }</p>
Custom tag comments
compoents Declaration Scriptlet Expression Directives Expression language Custom tags Comments HTML content
Jsp declaration Syntax Purpose Scope Example Visibility considerations
<%! // Declaration of a variable int count=0; // Declaration of a method void incrementcount (){ count++; } %>
USAGE OF JAVA BEANS IN A JSPAGE CREATING A JAVABEAN INSTANTIATING JAVABEAN IN JSP SETTING BEAN PROPERTIES ACCESSING BEAN PROPERTIES USING JAVABEAN METHODS SCOPE MANAGEMENT < jsp:useBean >
Public class userBean { Private string username; Private string email; //Default constructor public userBean (){ } // Getter and Setter methods for username public string getusername (){ Return username; } Public void setusername (string username){ this.username =username; } // Getter and setter methods for email Public string getEmail (); return email; } Public void setEmail (string email){ return email; } Public void setEmail (string email){ this.email =email; } }
DATA BASE IS ACCESSED USING A JSP PAGE DATABASE CONNECTION EXECUTING SQL QUERIES PROCESSING RESULTSET DISPLAYING DATA IN JSP CLOSING RESOURCES ERROR HANDLING
Explan how data base is accessed using a jsp page Database connection Executing sql quries Processing resultset Displaying data in jsp Closing resources Error handling