5.What are the implicit objects in JSP & differences between them?
There are nine implicit objects in JSP.
1. request : The request object represents httprequest that are trigged by service( ) invocation.
javax.servlet
2. response:The response object represents the servers response to request.
javax.servlet
3. pageContext : The page context specifies the single entry point to many of the page attributes and is the convient place to put shared data.
javax.servlet.jsp.pagecontext
4. session : the session object represents the session created by the current user.
javax.Servlet.http.HttpSession
5. application : the application object represents servlet context , obtained from servlet configaration .
javax.Servlet.ServletContext
6. out : the out object represents to write the out put stream .
javax.Servlet.jsp.jspWriter
7. config :the config object represents the servlet config interface from this page,and has scope attribute. javax.Servlet.ServletConfig
8. page : The object is the Instance of page implementation servlet class that are processing the current request.
java.lang.Object
9. exception : These are used for different purposes and actually u no need to create these objects in JSP. JSP container will create these objects automatically.
java.lang.Throwable
You can directly use these objects.
Example:
If i want to put my username in the session in JSP.
JSP Page: In the about page, i am using session object. But this session object is not declared in JSP file, because, this is implicit object and it will be created by the jsp container.
If u see the java file for this jsp page in the work folder of apache tomcat, u will find these objects are created.
6.What is jsp:usebean. What are the scope attributes & difference between these attributes?
page, request, session, application
7.What is difference between scriptlet and expression?
With expressions in JSP, the results of evaluating the expression are converted to a string and directly included within the output page. Typically expressions are used to display simple values of variables or return values by invoking a bean's getter methods. JSP expressions begin within tags and do not include semicolons:
But scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables or methods to use later in the file, write expressions valid in the page scripting language,use any of the JSP implicit objects or any object declared with a
8.What is Declaration ?
Declaration is used in JSP to declare methods and variables.To add a declaration, you must use the sequences to enclose your declarations.
9.How do you connect to the database from JSP ?
To be precise to connect jdbc from jsp is not good idea ofcourse if ur working on dummy projects connecting to msaccess u can very well use the same connection objects amd methods in ur scriplets and define ur connection object in init() method.
But if its real time u can use DAO design patterns which is widely used. for ex u write all ur connection object and and sql queries in a defined method later use transfer object [TO ]which is all ur fields have get/set methods and call it in business object[BO] so DAO is accessed with precaution as it is the crucial. Finally u define java bean which is a class holding get/set method implementing serialization thus the bean is called in the jsp. So never connect to jdbc directly from client side since it can be hacked by any one to get ur password or credit card info.
10.How do you call stored procedures from JSP ?
By using callable statement we can call stored procedures and functions from the database.
11.How do you restrict page errors display in the JSP page ?
set isErrorPage=false
12.How do you pass control from one JSP page to another ?
we can forward control to another jsp using jsp action tags forward or include
There are nine implicit objects in JSP.
1. request : The request object represents httprequest that are trigged by service( ) invocation.
javax.servlet
2. response:The response object represents the servers response to request.
javax.servlet
3. pageContext : The page context specifies the single entry point to many of the page attributes and is the convient place to put shared data.
javax.servlet.jsp.pagecontext
4. session : the session object represents the session created by the current user.
javax.Servlet.http.HttpSession
5. application : the application object represents servlet context , obtained from servlet configaration .
javax.Servlet.ServletContext
6. out : the out object represents to write the out put stream .
javax.Servlet.jsp.jspWriter
7. config :the config object represents the servlet config interface from this page,and has scope attribute. javax.Servlet.ServletConfig
8. page : The object is the Instance of page implementation servlet class that are processing the current request.
java.lang.Object
9. exception : These are used for different purposes and actually u no need to create these objects in JSP. JSP container will create these objects automatically.
java.lang.Throwable
You can directly use these objects.
Example:
If i want to put my username in the session in JSP.
JSP Page: In the about page, i am using session object. But this session object is not declared in JSP file, because, this is implicit object and it will be created by the jsp container.
If u see the java file for this jsp page in the work folder of apache tomcat, u will find these objects are created.
6.What is jsp:usebean. What are the scope attributes & difference between these attributes?
page, request, session, application
7.What is difference between scriptlet and expression?
With expressions in JSP, the results of evaluating the expression are converted to a string and directly included within the output page. Typically expressions are used to display simple values of variables or return values by invoking a bean's getter methods. JSP expressions begin within tags and do not include semicolons:
But scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables or methods to use later in the file, write expressions valid in the page scripting language,use any of the JSP implicit objects or any object declared with a
8.What is Declaration ?
Declaration is used in JSP to declare methods and variables.To add a declaration, you must use the sequences to enclose your declarations.
9.How do you connect to the database from JSP ?
To be precise to connect jdbc from jsp is not good idea ofcourse if ur working on dummy projects connecting to msaccess u can very well use the same connection objects amd methods in ur scriplets and define ur connection object in init() method.
But if its real time u can use DAO design patterns which is widely used. for ex u write all ur connection object and and sql queries in a defined method later use transfer object [TO ]which is all ur fields have get/set methods and call it in business object[BO] so DAO is accessed with precaution as it is the crucial. Finally u define java bean which is a class holding get/set method implementing serialization thus the bean is called in the jsp. So never connect to jdbc directly from client side since it can be hacked by any one to get ur password or credit card info.
10.How do you call stored procedures from JSP ?
By using callable statement we can call stored procedures and functions from the database.
11.How do you restrict page errors display in the JSP page ?
set isErrorPage=false
12.How do you pass control from one JSP page to another ?
we can forward control to another jsp using jsp action tags forward or include