Is JSP extensible ?
Except JSP directives (<%@ %>), declarations (<% %>), scriptlets (<% %>) and expressions (<%= %>), PolyJsp introduces a few (optional) extensions to JSP :
* A <%@ version="..." > directive
Useful to instruct the parser to use a version other than the default (currently 0.92)
* A <%@ contenttype="..."> directive
Useful for cases in which the expected output MIME type is other than text/html
* A <header name="..." value="...">
Useful to set response headers. Example: set expires to control browser chaching Reply
What are the different scopes available ?
Scope tells accessibility of the object in the web application. JSP has the following scopes :
What are the implicit objects?
Web container provides developer to access some objects instantiated by container and available to all the jsp pages. These objects are called implicit objects because they are automatically instantiated. Within each JSP application is the complete set of implicit objects.
There are nine implicit objects in JSP.
9. page Reply
What is a Scriptlet?
Scriptlet is a JSP element. It contains the java code enclosed within <% and %>. JSP Engine places these code in the _jspService() method.
Syntax of JSP Scriptles are:
System.out.println( "Current Date is:" );
java.util.Date date = new java.util.Date();
Hello <%= userName %> ! <br>
The time is now :<%= date %>
What is a Declaration?
You must declare the variable or method before you use it in the JSP page. The Declaration is a JSP element use to declare the variable or methods that you can use in Java code later in the JSP page.
JSP Declaration :
<%! code %> :- Code is inserted in body of servlet class, outside of service method.
Example : The declaration must be valid in the scripting language used in the JSP file.
<%! int i = 0; %>
<%! int a, b, c; %>Reply
What is a Expression?
Expression in JSP is used to write the output on the stream. It has the following form :
<%= Java Expression %>
The Java expression is evaluated, converted to a string, and inserted in the page. This evaluation is performed at run-time and thus has full access to information about the request. For example, the following shows the date/time that the page was requested:
Current time is : <%= new java.util.Date() %>
What are context initialization parameters?
Context initialization parameters are defined in the Deployment descriptor an accessible to all the servlets in the application. You can use context initialization parameters to specify the information that is dynamically change. You can also use these to specify the URL of the database.
<param-value>email@example.com</param-value> </context-param> Reply
How can I implement a thread-safe JSP page?
To make your JSPs thread-safe, you hace to implement the SingleThreadModel interface.
This can be done by using page directive with isThreadSafe attribute by setting it to false:
<%@ page isThreadSafe="false" %>
How do I include static files within a JSP page?
We can include static files within a JSP page using the include directive :
< % @ include file="top.html" % >
How many JSP scripting elements are there and what are they?
Types of Scripting Elements
� Expressions :
<%= expression %> :� Evaluated and inserted into the servlet�s output, i.e., results in something like out.print(expression)
� Scriptlets :
<% code %> :� Inserted verbatim into the servlet�s _jspService method (called by
� Declarations :
<%! code %> :- Inserted verbatim into the body of the servlet class, outside of any
� Directive :
<%@ directive %> :- To use "import" statements in JSPs.