31. How is scripting disabled?
Scripting is disabled by setting the scripting-invalid element of the deployment descriptor to true. It is a subelement of jsp-property-group. Its valid values are true and false. The syntax for disabling scripting is as follows:
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<scripting-invalid>true</scripting-invalid>
</jsp-property-group>
32. What are the JSP implicit objects?
Implicit objects are by default available to the JSP. Being JSP author we can use these and not required to create it explicitly.
- request
- response
- pageContext
- session
- application
- out
- config
- page
- exception
33. How does JSP handle run-time exceptions?
You can use the errorPage attribute of the page directive to have uncaught run-time exceptions automatically forwarded to an error processing page.
For example:
<%@ page errorPage="error.jsp" %> redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request processing.
<%@ page errorPage="error.jsp" %> redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request processing.
Within error.jsp, if you indicate that it is an error-processing page, via the directive:
<%@ page isErrorPage="true" %>
In the error pages we can access exception implicit object.34. How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?
You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive in the JSP.
<%@ page isThreadSafe="false" %>
The generated servlet can handle only one client request at time so that we can make JSP as thread safe. We can overcome data inconsistency problems by this approach.
The main limitation is it may affect the performance of the system.
35. What is the difference between ServletContext and PageContext?
ServletContext: Gives the information about the container and it represents an application. PageContext: Gives the information about the Request and it can provide all other implicit JSP objects .
Yes, there is. The page implicit object is equivalent to "this", and returns a reference to the generated servlet.
37 . Can you make use of a ServletOutputStream object from within a JSP page?
Yes . By using getOutputStream() method on response implicit object we can get it.
38 .What is the page directive is used to prevent a JSP page from automatically creating a session?
session object is by default available to the JSP. We can make it unavailable by using page directive as follows.
<%@ page session="false">
39. What's a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?
Synchronized keyword is recommended to use to get thread-safety.
40. What are various attributes Of Page Directive ?
Page directive contains the following 13 attributes.
- language
- extends
- import
- session
- isThreadSafe
- info
- errorPage
- isError page
- contentType
- isELIgnored
- buffer
- autoFlush
- pageEncoding.
0 comments:
Post a Comment