JSP FAQs - 4

Author Shaf Category

 

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>

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.

  1. request
  2. response
  3. pageContext
  4. session
  5. application
  6. out
  7. config
  8. page
  9. 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.

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 .

36 . Is there a way to reference the "this" variable within a JSP page?

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.

  1. language
  2. extends
  3. import
  4. session
  5. isThreadSafe
  6. info
  7. errorPage
  8. isError page
  9. contentType
  10. isELIgnored
  11. buffer
  12. autoFlush
  13. pageEncoding

 

0 comments:

Post a Comment

Theme by New wp themes | Bloggerized by Dhampire