How to refer the "this" variable within a JSP page?
Under JSP 1.0, the "page" implicit object page is equivalent to "this", and returns a reference to the servlet generated by the JSP page. Reply
How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
By setting HTTP header attributes you can prevent the output of my JSP or Servlet pages from being cached by the browser. You can do this by the following code :
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
Can I just abort processing a JSP?
Yes! We can abort the processing of JSP because at the end every JSP file turned into a servlet and we can put a return statement into the service method, so we can put a return statement into JSP code, i.e. we can put <% return; %> into the JSP file.Reply
What is the difference between <%@ include ...> (directive include) and <jsp:include> ?
The include directive :-
<%@ include file="fileName" %>
is static and processed at the time when the JSP page is translated into its equivalent servlet. The file included in the page at the time translation and compiled file also contain the included file code. This directive is normally used for including static resources only - like, banner, header, footer, etc. If you make some changes in the included file then it will not affect those files which had included this file.
The include action :-
<jsp:include page="relativeURL" />
is dynamic and processed at runtime. This will simply make a function call at run time to the included file. This action allows additional parameters to be passed via <jsp:param> child element of this include action element. If you make some changes in the included file then it will also affect those files which had included this file.Reply
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() %>