How do you pass data (including JavaBeans) to a JSP from a servlet?
You can pass information to a JSP page from the servlet. Using setAttribut() on request object in the servlet and forward it as follows :
RequestDispatcher rd =
How to pass information from JSP to included JSP?
You can pass information from JSP to the included JSP using the <jsp:param> in the body of <jsp:include> action.
<jsp:param name="parameterName" value="parameterValue"/>
What is a Hidden Comment?
A hidden comment is a JSP comment that is not sent to the client. Syntax :
<%-- Hidden comment --%>Reply
What is the difference between ServletContext and ServletConfig?
ServletContext and ServletConfig are declared in the deployment descriptor. ServletConfig is one per servlet and can be accessed only within that specific servlet. ServletContext is one per web application and accessible to all the servlet in the web application.Reply
What are JSP Actions?
JSP Actions are XML tags that are executed at run time. These tags transfer the control between the pages and also use the server side beans :
Some JSP Actions are :
How do I use a scriptlet to initialize a newly instantiated bean?
The <jsp:useBean> may also optionally have a body. You can make use of a JSP expression within the <jsp:setProperty> action in the body of <jsp:useBean>.
For Example :
<jsp:useBean id="foo" class="Bar.Foo" >
<jsp:setProperty name="foo" property="today" value="<%=java.text.DateFormat.getDateInstance().format(new java.util.Date()) %>" / >
</jsp:useBean > Reply
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