<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; Jsp Inteview Questions</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/jsp-inteview-questions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 30 Jul 2010 06:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Jsp Example: File Uploading</title>
		<link>http://www.bestjavainterviewquestions.com/jsp-example-file-uploading/</link>
		<comments>http://www.bestjavainterviewquestions.com/jsp-example-file-uploading/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 08:07:11 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[File Uploading using Java/Jsp]]></category>
		<category><![CDATA[file uploading example using jsp]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=527</guid>
		<description><![CDATA[FileUploading Using JSP(JAVA) This is an example of the file Uploading in Java using JSP . This file uploading concept Works with the Java as follows This Java  API parses InputStream of HttpPost request with multipart/form-data encode. By this Java API, only the single method call is enough for your file upload using jsp.In  this [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><strong>FileUploading Using JSP(JAVA)</strong></span></p>
<p>This is an example of the file Uploading in Java using JSP . This file uploading concept Works with the Java as follows</p>
<p>This Java  API parses <em>InputStream of HttpPost request with <strong>multipart/form-data encode</strong>.</em> By this Java API, only the single method call is enough for your file upload using jsp.In  this example the the file(image) will be saved in your server automatically after you run the application in the Server.</p>
<p>The server takes the default path as the destination if you not specified any path by hard coded.</p>
<p>Using the<em> multipart/form-data</em> you are saying to the server that the request is of type multipart and the data is encrypted data</p>
<p>Intially you have to design the  html file</p>
<p>1)First create the html file by using</p>
<p>&#8211;&gt; the file tag in the form attribute(&lt;input type=file name=file1&gt;<br />
&#8211;&gt;use the submit tag to send the request to the jsp page.</p>
<p><strong>name these page as the fileupload.html </strong></p>
<p><em>&lt;form method=&#8221;post&#8221; action=&#8221;/fileUpload.jsp&#8221; name=&#8221;upform&#8221; enctype=&#8221;multipart/form-data&#8221;&gt;<br />
&lt;table width=&#8221;60%&#8221; border=&#8221;0&#8243; cellspacing=&#8221;1&#8243; cellpadding=&#8221;1&#8243; align=&#8221;center&#8221; class=&#8221;style1&#8243;&gt;<br />
&lt;tr&gt;<br />
&lt;td align=&#8221;left&#8221;&gt;&lt;b&gt;Select a file to upload :&lt;/b&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td align=&#8221;left&#8221;&gt;<br />
&lt;input type=&#8221;file&#8221; name=&#8221;uploadfile&#8221; size=&#8221;50&#8243;&gt;<br />
&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;tr&gt;<br />
&lt;td align=&#8221;left&#8221;&gt;<br />
&lt;input type=&#8221;submit&#8221; name=&#8221;Submit&#8221; value=&#8221;Upload&#8221;&gt;<br />
&lt;input type=&#8221;reset&#8221; name=&#8221;Reset&#8221; value=&#8221;Cancel&#8221;&gt;<br />
&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt; </em></p>
<p>Once the request goes to the jsp the request is collected through getContentType() method (to learn about <a class="wp-caption" title="Javax.Servlet Interface" href="http://computerpreferedcourses.blogspot.com/2009/01/javaxservlet-interface-servletrequest.html" target="_blank">getContentType</a>)</p>
<p>Then Using the InputSreams and OutputStream the data is modified and do what the way you want the output to show</p>
<p>Name this Jsp file as <em><strong>fileUpload</strong> <strong>.jsp</strong> </em>Your program will run now<em><br />
</em></p>
<p><em>&lt;%@ page import=&#8221;java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream&#8221; %&gt;<br />
&lt;%@ page import=&#8221;java.io.FileWriter,java.io.IOException,java.io.PrintWriter,java.text.DecimalFormat&#8221; %&gt;<br />
&lt;%@ page import=&#8221;java.sql.*&#8221; %&gt;<br />
&lt;%<br />
String filename = &#8220;&#8221;;<br />
String contentType = &#8220;&#8221;, fileData = &#8220;&#8221;, strLocalFileName = &#8220;&#8221;;<br />
int startPos = 0, endPos = 0;<br />
%&gt;<br />
&lt;%!<br />
//copy specified number of bytes from main data buffer to temp data buffer</em></p>
<p><em>void copyByte(byte [] fromBytes, byte [] toBytes, int start, int len)<br />
{<br />
for(int i=start;i&lt;(start+len);i++)<br />
{<br />
toBytes[i - start] = fromBytes[i];<br />
}<br />
}<br />
%&gt;<br />
&lt;%<br />
contentType = request.getContentType();<br />
//out.println(&#8220;&lt;br&gt;Content type is :: &#8221; +contentType);<br />
if ((contentType != null) &amp;&amp; (contentType.indexOf(&#8220;multipart/form-data&#8221;) &gt;= 0))<br />
{<br />
DataInputStream in = new DataInputStream(request.getInputStream());<br />
DataInputStream in1 = in;<br />
int formDataLength = request.getContentLength();<br />
byte dataBytes[] = new byte[formDataLength];<br />
int byteRead = 0;<br />
int totalBytesRead = 0;<br />
while (totalBytesRead &lt; formDataLength)<br />
{<br />
byteRead = in1.read(dataBytes, totalBytesRead, formDataLength);<br />
totalBytesRead += byteRead;<br />
}<br />
//out.println(&#8220;&lt;br&gt;totalBytesRead : &#8221; + totalBytesRead + &#8220;    :   formDataLength = &#8221; + formDataLength);</em></p>
<p><em>//String file = new String(dataBytes);<br />
//out.println(&#8220;&lt;br&gt;File Contents:&lt;br&gt;////////////////////////////////////&lt;br&gt;&#8221; + file + &#8220;&lt;br&gt;////////////////////////////////&lt;br&gt;&#8221;);<br />
byte[] line = new byte[128];<br />
if (totalBytesRead &lt; 3)<br />
{<br />
return;    //exit if file length is not sufficiently large<br />
}</em></p>
<p><em>String boundary = &#8220;&#8221;;<br />
String s = &#8220;&#8221;;<br />
int count = 0;<br />
int pos = 0;</em></p>
<p><em>//loop for extracting boundry of file</em></p>
<p><em>//could also be extracted from request.getContentType()</em></p>
<p><em>do<br />
{<br />
copyByte(dataBytes, line, count ,1);    //read 1 byte at a time<br />
count+=1;<br />
s = new String(line, 0, 1);<br />
fileData = fileData + s;<br />
pos = fileData.indexOf(&#8220;Content-Disposition: form-data; name=\&#8221;"); //set the file name<br />
if(pos != -1)<br />
endPos = pos;<br />
}while(pos == -1);<br />
boundary = fileData.substring(startPos, endPos);</em></p>
<p><em>//loop for extracting filename</em></p>
<p><em>startPos = endPos;<br />
do<br />
{<br />
copyByte(dataBytes, line, count ,1);    //read 1 byte at a time<br />
count+=1;<br />
s = new String(line, 0, 1);<br />
fileData = fileData + s;<br />
pos = fileData.indexOf(&#8220;filename=\&#8221;", startPos);  //set the file name<br />
if(pos != -1)<br />
startPos = pos;<br />
}while(pos == -1);<br />
do<br />
{<br />
copyByte(dataBytes, line, count ,1);    //read 1 byte at a time<br />
count+=1;<br />
s = new String(line, 0, 1);<br />
fileData = fileData + s;<br />
pos = fileData.indexOf(&#8220;Content-Type: &#8220;, startPos);<br />
if(pos != -1)<br />
endPos = pos;<br />
}while(pos == -1);</em></p>
<p><em>//to eliminate &#8221; from start &amp; end</em></p>
<p><em>filename = fileData.substring(startPos + 10, endPos &#8211; 3);</em></p>
<p><em>strLocalFileName = filename;<br />
int index = filename.lastIndexOf(&#8220;\\&#8221;);<br />
if(index != -1)<br />
filename = filename.substring(index + 1);<br />
else<br />
filename = filename;</em></p>
<p><em>s = new String(line, 0, 1);<br />
fileData = fileData + s;</em></p>
<p><em>//for invoking the value of starting address path</em></p>
<p><em>int pic1=fileData.lastIndexOf(&#8220;=&#8221;)+1;</em></p>
<p><em>// for invoking the value of ending address path</em></p>
<p><em>int pic2=fileData.lastIndexOf(&#8220;C&#8221;)-1;<br />
int img1=pic1+1;<br />
int img2=pic2-2;</em></p>
<p><em>// for getting the abs path using substring</em></p>
<p><em>String filename2=fileData.substring(img1,img2);</em></p>
<p><em>// for getting the abs path without quots</em></p>
<p><em>filename=fileData.substring(pic1,pic2);</em></p>
<p><em>// invoking the file name  without quots</em></p>
<p><em>int path=filename2.lastIndexOf(&#8220;\\&#8221; )+1;<br />
String path1=filename2.substring(path);</em></p>
<p><em>// invoing the file extension without quots</em></p>
<p><em>int lastpath=filename2.lastIndexOf(&#8220;.&#8221;)+1;<br />
String lastpath1=filename2.substring(lastpath);<br />
System.out.println(&#8221; output &#8220;+filename);<br />
out.println(&#8220;&lt;img src=&#8221;+filename+&#8221;&gt;&lt;/img&gt;&#8221;);</em></p>
<p><em>FileOutputStream fileOut = new FileOutputStream(filename);<br />
fileOut.write(dataBytes, startPos, (endPos &#8211; startPos));<br />
fileOut.flush();<br />
fileOut.close();<br />
}<br />
else<br />
{<br />
out.println(&#8220;Error in uploading &#8220;);<br />
}</em></p>
<p><em>%&gt; </em></p>
<p>Your image will be saved in path where your server installed</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/collection-framework/" title="Collection FrameWork"><img src="Array" alt="Collection FrameWork" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/software-architecture-of-ejb/" title="Software  Architecture of EJB"><img src="Array" alt="Software  Architecture of EJB" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/jsp-interview-questions/" title="JSP Interview Questions"><img src="Array" alt="JSP Interview Questions" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/jsp-scriplets-and-templets/" title="Jsp Scriplets and Templets"><img src="Array" alt="Jsp Scriplets and Templets" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/difference-between-sessionsave-and-sessionsaveorupdate-4/" title="Difference between session.save() and session.saveOrUpdate()"><img src="Array" alt="Difference between session.save() and session.saveOrUpdate()" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/jsp-example-file-uploading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>when do use application scope</title>
		<link>http://www.bestjavainterviewquestions.com/when-do-use-application-scope/</link>
		<comments>http://www.bestjavainterviewquestions.com/when-do-use-application-scope/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 17:48:55 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[define application scope]]></category>
		<category><![CDATA[application scope]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=445</guid>
		<description><![CDATA[Application Scope If a single Java Bean Object that holds nothing specific to the client has to be used while processing multiple requests then we must use scope=&#8221;application&#8221; For every application there will be several application preferences/setting we can store the application preferences as part of a table in DataBase as part of an XML [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="text-decoration: underline;">Application Scope</span></strong></p>
<p>If a single Java Bean Object that holds nothing specific to the client has to be used while processing multiple requests then we must use scope=&#8221;application&#8221;</p>
<p>For every application there will be several application preferences/setting we can store the application preferences as part of a table in DataBase as part of an XML file/as part of a flat file.</p>
<p>We can use an xml as shown below to hold the information about the application preference</p>
<p><strong><em>Note:</em></strong> Storing the object inside the <em>servletcontext</em> is an application scope</p>
<p><em>Syntax:</em></p>
<p>&lt;host-app&gt;</p>
<p>&lt;pref-name&gt;hname&lt;/pref-name&gt;</p>
<p>&lt;pref-value&gt;Hospitalone&lt;/pref-value&gt;</p>
<p>&lt;pref-name&gt;address&lt;/pref-name&gt;</p>
<p>&lt;pref-value&gt;Srnagar&lt;/pref-value&gt;</p>
<p>&lt;pref-name&gt;bgcolor&lt;/pref-name&gt;</p>
<p>&lt;pref-value&gt;blue&lt;/pref-value&gt;</p>
<p>&lt;pref-name&gt;logo&lt;/pref-name&gt;</p>
<p>&lt;pref-value&gt;hlogo.jsp&lt;/pref-value&gt;</p>
<p>&lt;/hosp-app&gt;</p>
<p>save the above code with the extension<strong> app-conf.xml</strong></p>
<p>The above data is not specific to the client and is required while processing multiple request.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/converting-hibernate-with-eclipse-integration/" title="Converting Hibernate with Eclipse Integration"><img src="Array" alt="Converting Hibernate with Eclipse Integration" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/difference-between-stateful-and-stateless-session-bean/" title="Difference Between StateFul and Stateless Session Bean"><img src="Array" alt="Difference Between StateFul and Stateless Session Bean" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/hibernate-introduction/" title="Hibernate Introduction"><img src="Array" alt="Hibernate Introduction" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/write-a-short-notes-on-vectors/" title="Write a Short notes on Vectors"><img src="Array" alt="Write a Short notes on Vectors" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/define-session-hijacking-2/" title="Define Session Hijacking"><img src="Array" alt="Define Session Hijacking" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/when-do-use-application-scope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Define Precompile of Jsp page</title>
		<link>http://www.bestjavainterviewquestions.com/define-precompile-of-jsp-page/</link>
		<comments>http://www.bestjavainterviewquestions.com/define-precompile-of-jsp-page/#comments</comments>
		<pubDate>Tue, 30 Sep 2008 16:16:48 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Define Precompile of Jsp page]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[precompiling jsp]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=391</guid>
		<description><![CDATA[Q) How do you precompile a jsp page? A) To precompile a JSP page, access the page with a query string of ?jsp_precompile http://www.javagalaxy.com:8080/RMI/index.jsp?jsp_precompile the jsp page will not get executed by this action. Related Post]]></description>
			<content:encoded><![CDATA[<p><strong> Q) How do you precompile a jsp page?</strong></p>
<p><strong>A)</strong> To precompile a JSP page, access the page with a query string of ?jsp_precompile</p>
<p>http://www.javagalaxy.com:8080/RMI/index.jsp?jsp_precompile</p>
<p>the jsp page will not get executed by this action.</p>
<h2  class="related_post_title">Related Post</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/calling-a-method-in-java/" title="Calling a Method in Java"><img src="Array" alt="Calling a Method in Java" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/what-is-api/" title="What is API"><img src="Array" alt="What is API" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/what-is-jre-explain/" title="What is JRE ? Explain"><img src="Array" alt="What is JRE ? Explain" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/explain-session-tracking-using-servlet/" title="Explain Session tracking using Servlet"><img src="Array" alt="Explain Session tracking using Servlet" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/why-does-ejb-needs-two-interfaces/" title="Why does EJB needs two interfaces"><img src="Array" alt="Why does EJB needs two interfaces" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/define-precompile-of-jsp-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSP Standard Questions</title>
		<link>http://www.bestjavainterviewquestions.com/jsp-standard-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/jsp-standard-questions/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 17:01:34 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Jsp Inteview Questions]]></category>
		<category><![CDATA[jsp important and repeated questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=41</guid>
		<description><![CDATA[Q) Can I invoke a JSP error page from a servlet? A) Yes, you can invoke the JSP error page and pass the exception object to it from within a servlet. The trick is to create a request dispatcher for the JSP error page, and pass the exception object as a javax.servlet.jsp.jspException request attribute. However, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) Can I invoke a JSP error page from a servlet?<br />
A) </strong>Yes, you can invoke the JSP error page and pass the exception object to it from within a servlet. The trick is to create a request dispatcher for the JSP error page, and pass the exception object as a javax.servlet.jsp.jspException request attribute. However, note that you can do this from only within controller servlets. If your servlet opens an OutputStream or PrintWriter, the JSP engine will throw the following translation error:<br />
java.lang.IllegalStateException: Cannot forward as OutputStream or Writer has already been obtained<br />
The following code snippet demonstrates the invocation of a JSP error page from within a controller servlet:<br />
protected void sendErrorRedirect(HttpServletRequest request, HttpServletResponse response, String errorPageURL, Throwable e) throws ServletException, IOException<br />
{<br />
request.setAttribute (&#8220;javax.servlet.jsp.jspException&#8221;, e);<br />
getServletConfig().getServletContext(). getRequestDispatcher(errorPageURL).forward(request, response);<br />
}</p>
<p>public void doPost(HttpServletRequest request, HttpServletResponse response)<br />
{<br />
try {<br />
// do something<br />
} catch (Exception ex)<br />
{<br />
try {<br />
sendErrorRedirect(request,response,&#8221;/jsp/MyErrorPage.jsp&#8221;,ex);<br />
} catch (Exception e)<br />
{<br />
e.printStackTrace();<br />
}          }      }</p>
<p><strong>Q) How can you store international / Unicode characters into a cookie?<br />
A) </strong>One way is, before storing the cookie URLEncode it.<br />
URLEnocder.encoder(str);<br />
And use URLDecoder.decode(str) when you get the stored cookie.<br />
<strong><br />
Q) What are the implicit objects?<br />
A) </strong>Implicit objects are objects that are created by the web container and contain information related to a particular request, page, or application. They are:<br />
request<br />
response<br />
pageContext<br />
session<br />
application<br />
out<br />
config<br />
page<br />
exception</p>
<p><strong>Q) Is JSP technology extensible?<br />
A)</strong> YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries<br />
<strong><br />
</strong><br />
<strong><br />
Q) How does JSP handle run-time exceptions?<br />
A)</strong> 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:</p>
<p>&lt;%@ page errorPage=&#8221;error.jsp&#8221; %&gt;</p>
<p>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:</p>
<p>&lt;%@ page isErrorPage=&#8221;true&#8221; %&gt;</p>
<p>the Throwable object describing the exception may be accessed within the error page via the exception implicit object.</p>
<p><strong>Q) How do I prevent the output of my JSP or Servlet pages from being cached by the browser?<br />
A)</strong> You will need to set the appropriate HTTP header attributes to prevent the dynamic content output by the JSP page from being cached by the browser. Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser. You need both the statements to take care of some of the older browser versions.<br />
&lt;%<br />
response.setHeader(&#8220;Cache-Control&#8221;,&#8221;no-store&#8221;); //HTTP 1.1<br />
response.setHeader(&#8220;Pragma&#8221;,&#8221;no-cache&#8221;); //HTTP 1.0<br />
response.setDateHeader (&#8220;Expires&#8221;, 0); //prevents caching at the proxy server<br />
%&gt;</p>
<p><strong>Q) How does a servlet communicate with a JSP page?<br />
A)</strong> The following code snippet shows how a servlet instantiates a bean and initializes it with FORM data posted by a browser. The bean is then placed into the request, and the call is then forwarded to the JSP page, Bean1.jsp, by means of a request dispatcher for downstream processing.<br />
public void doPost (HttpServletRequest request, HttpServletResponse response)<br />
{<br />
try {<br />
govi.FormBean f = new govi.FormBean();<br />
String id = request.getParameter(&#8220;id&#8221;);<br />
f.setName(request.getParameter(&#8220;name&#8221;));<br />
f.setAddr(request.getParameter(&#8220;addr&#8221;));<br />
f.setAge(request.getParameter(&#8220;age&#8221;));<br />
//use the id to compute<br />
//additional bean properties like info<br />
//maybe perform a db query, etc.<br />
// . . .<br />
f.setPersonalizationInfo(info);<br />
request.setAttribute(&#8220;fBean&#8221;,f);<br />
getServletConfig().getServletContext().getRequestDispatcher<br />
(&#8220;/jsp/Bean1.jsp&#8221;).forward(request, response);<br />
}<br />
catch (Exception ex)<br />
{<br />
. . .<br />
}<br />
}<br />
The JSP page Bean1.jsp can then process fBean, after first extracting it from the default request scope via the useBean action.<br />
jsp:useBean id=&#8221;fBean&#8221; class=&#8221;govi.FormBean&#8221; scope=&#8221;request&#8221;/ jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;name&#8221; / jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;addr&#8221; / jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;age&#8221; / jsp:getProperty name=&#8221;fBean&#8221; property=&#8221;personalizationInfo&#8221; /</p>
<p><strong>Q) How do I have the JSP-generated servlet subclass my own custom servlet class, instead of the default?<br />
A) </strong>One should be very careful when having JSP pages extend custom servlet classes as opposed to the default one generated by the JSP engine. In doing so, you may lose out on any advanced optimization that may be provided by the JSP engine. In any case, your new superclass has to fulfill the contract with the JSP engine by:<br />
Implementing the HttpJspPage interface, if the protocol used is HTTP, or implementing JspPage otherwise Ensuring that all the methods in the Servlet interface are declared final Additionally, your servlet superclass also needs to do the following:<br />
The service() method has to invoke the _jspService() method<br />
The init() method has to invoke the jspInit() method<br />
The destroy() method has to invoke jspDestroy()<br />
If any of the above conditions are not satisfied, the JSP engine may throw a translation error.<br />
Once the superclass has been developed, you can have your JSP extend it as follows:<br />
&lt;%@ page extends=&#8221;packageName.ServletName&#8221; %&gt;</p>
<p><strong>Q) How can I prevent the word &#8220;null&#8221; from appearing in my HTML input text fields when I populate them with a resultset that has null values?<br />
A)</strong> You could make a simple wrapper function, like<br />
&lt;%!<br />
String blanknull(String s)<br />
{<br />
return (s == null) ? &#8220;&#8221; : s;<br />
}<br />
%&gt;</p>
<p>then use it inside your JSP form, like</p>
<p>&lt;input type=&#8221;text&#8221; name=&#8221;shoesize&#8221; value=&#8221;&lt;%=blanknull(shoesize)% &gt;&#8221; &gt;<br />
<strong><br />
Q) How do you prevent the Creation of a Session in a JSP Page and why?<br />
A)</strong> By default, a JSP page will automatically create a session for the request if one does not exist. However, sessions consume resources and if it is not necessary to maintain a session, one should not be created. For example, a marketing campaign may suggest the reader visit a web page for more information. If it is anticipated that a lot of traffic will hit that page, you may want to optimize the load on the machine by not creating useless sessions.</p>
<p>The page directive is used to prevent a JSP page from automatically creating a session:<br />
&lt;%@ page session=&#8221;false&#8221;&gt;<br />
<strong></p>
<p></strong></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/define-session-hijacking-3/" title="Define Session Hijacking"><img src="Array" alt="Define Session Hijacking" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/explain-java-comments/" title="Explain Java Comments"><img src="Array" alt="Explain Java Comments" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/explain-session-destroy-in-servlets/" title="Explain session destroy in Servlets"><img src="Array" alt="Explain session destroy in Servlets" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/java-garbage-collections/" title="Java Garbage Collections"><img src="Array" alt="Java Garbage Collections" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/jdbc-interview-questions/" title="Jdbc Interview Questions"><img src="Array" alt="Jdbc Interview Questions" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/jsp-standard-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSP Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/jsp-interview-questions-2/</link>
		<comments>http://www.bestjavainterviewquestions.com/jsp-interview-questions-2/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 16:54:42 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Jsp Inteview Questions]]></category>
		<category><![CDATA[jsp important questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=40</guid>
		<description><![CDATA[Q) What is the difference between ServletContext and PageContext? A) ServletContext: Gives the information about the container PageContext: Gives the information about the Request Q) What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()? A) request.getRequestDispatcher(path): In order to create it we need to give the relative path of   the  resource. context.getRequestDispatcher(path): In order to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) What is the difference between ServletContext and PageContext?<br />
A)</strong> ServletContext: Gives the information about the container<br />
PageContext: Gives the information about the Request</p>
<p><strong>Q) What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?<br />
A)</strong> request.getRequestDispatcher(path): In order to create it we need to give the relative path of   the  resource.<br />
context.getRequestDispatcher(path): In order to create it we need to give the absolute path of the resource.<br />
<strong><br />
Q) How to pass information from JSP to included JSP?<br />
A) </strong>Using &lt;%jsp:param&gt; tag.</p>
<p><strong>Q) What is the difference between directive include and jsp include?<br />
A)</strong> &lt;%@ include&gt; : Used to include static resources during translation time.<br />
: Used to include dynamic content or static content during runtime.</p>
<p><strong>Q) What is the difference between RequestDispatcher and sendRedirect?<br />
A)</strong> RequestDispatcher: server-side redirect with request and response objects.<br />
sendRedirect : Client-side redirect with new request and response objects.</p>
<p><strong>Q) How does JSP handle runtime exceptions?<br />
A)</strong> Using errorPage attribute of page directive and also we need to specify isErrorPage=true if the current page is intended to URL redirecting of a JSP.<br />
<strong><br />
Q) How do you delete a Cookie within a JSP?<br />
A) </strong>Cookie mycook = new Cookie(&#8220;name&#8221;,&#8221;value&#8221;);<br />
response.addCookie(mycook);</p>
<p>Cookie killmycook = new Cookie(&#8220;mycook&#8221;,&#8221;value&#8221;);<br />
killmycook.setMaxAge(0);<br />
killmycook.setPath(&#8220;/&#8221;);<br />
killmycook.addCookie(killmycook);</p>
<p><strong>Q) How do I mix JSP and SSI #include?<br />
A)</strong> If you&#8217;re just including raw HTML, use the #include directive as usual inside your .jsp file.            &lt;!&#8211;#include file=&#8221;data.inc&#8221;&#8211;&gt;<br />
But it&#8217;s a little trickier if you want the server to evaluate any JSP code that&#8217;s inside the included file. Ronel Sumibcay (ronel@LIVESOFTWARE.COM) says:<br />
If your data.inc  file contains jsp code you will have to use<br />
&lt;%@ vinclude=&#8221;data.inc&#8221; %&gt;<br />
The &lt;!&#8211;#include file=&#8221;data.inc&#8221;&#8211;&gt;  is used for including non-JSP files.</p>
<p><strong>Q) What is the difference between Model 1 and Model 2 architecture?<br />
A)</strong> In Model 1 there is no Controller and in Model 2 there is a Controller.<br />
<strong><br />
Q) How can my application get to know when a HttpSession is removed?<br />
A) </strong>Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method.<br />
Create an instance of that class and put that instance in HttpSession.</p>
<p><strong>Q) How can I implement a thread-safe JSP page?<br />
A)</strong> You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive &lt;%@ page isThreadSafe=&#8221;false&#8221; % &gt; within your JSP page.<br />
<strong><br />
Q) How many JSP scripting elements are there and what are they?<br />
A)</strong> There are three scripting language elements:<br />
declarations<br />
scriptlets<br />
expressions<br />
<strong><br />
Q) In the Servlet 2.4 specification SingleThreadModel has been deprecates, why?<br />
A)</strong> Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level.</p>
<p><strong>Q) How do I include static files within a JSP page?<br />
A) </strong>Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. The following example shows the syntax: Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.<br />
<strong><br />
Q) How do I mix JSP and SSI #include?<br />
A)</strong> If you&#8217;re just including raw HTML, use the #include directive as usual inside your .jsp file.<br />
&lt;!&#8211;#include file=&#8221;data.inc&#8221;&#8211;&gt;<br />
But it&#8217;s a little trickier if you want the server to evaluate any JSP code that&#8217;s inside the included file. If your data.inc file contains jsp code you will have to use<br />
&lt;%@ vinclude=&#8221;data.inc&#8221; %&gt;<br />
The &lt;!&#8211;#include file=&#8221;data.inc&#8221;&#8211;&gt; is used for including non-JSP files.</p>
<p><strong>Q) Can a JSP page process HTML FORM data?<br />
A)</strong> Yes. However, unlike servlets, you are not required to implement HTTP-protocol specific methods like doGet() or doPost() within your JSP page. You can obtain the data for the FORM input elements via the request implicit object within a scriptlet or expression as:<br />
&lt;%<br />
String item = request.getParameter(&#8220;item&#8221;);<br />
int howMany = new Integer(request.getParameter(&#8220;units&#8221;)).intValue();<br />
%&gt;<br />
or<br />
&lt;%= request.getParameter(&#8220;item&#8221;) %&gt;</p>
<p><strong>Q) What JSP lifecycle methods can I override?<br />
A) </strong>You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database connections, network connections, and so forth for the JSP page. It is good programming practice to free any allocated resources within jspDestroy(). The jspInit() and jspDestroy() methods are each executed just once during the lifecycle of a JSP page and are typically declared as JSP declarations:<br />
&lt;%!<br />
public void jspInit() {<br />
. . .<br />
}<br />
%&gt;<br />
&lt;%!<br />
public void jspDestroy() {<br />
. . .<br />
}<br />
%&gt;</p>
<p><strong>Q) How do I include static files within a JSP page?<br />
A) </strong>Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. The following example shows the syntax:</p>
<p>&lt;%@ include file=&#8221;copyright.html&#8221; %&gt;</p>
<p>Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.</p>
<p><strong>Q) How do I perform browser redirection from a JSP page?<br />
A)</strong> You can use the response implicit object to redirect the browser to a different resource, as:<br />
response.sendRedirect(&#8220;http://www.foo.com/path/error.html&#8221;);<br />
You can also physically alter the Location HTTP header attribute, as shown below:<br />
&lt;%<br />
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);<br />
String newLocn = &#8220;/newpath/index.html&#8221;;<br />
response.setHeader(&#8220;Location&#8221;,newLocn);<br />
%&gt;<br />
You can also use the:<br />
&lt;jsp:forward page=&#8221;/newpage.jsp&#8221; /&gt; Also note that you can only use this before any output has been sent to the client. I beleve this is the case with the response.sendRedirect() method as well.<br />
If you want to pass any paramateres then you can pass using &lt;jsp:forward page=&#8221;/servlet/login&#8221;&gt; &lt;jsp:param name=&#8221;username&#8221; value=&#8221;jsmith&#8221; /&gt; &lt;/jsp:forward&gt;&gt;</p>
<p>Q) Can a JSP page instantiate a serialized bean?<br />
A) No problem! The useBean action specifies the beanName attribute, which can be used for indicating a serialized bean. For example:</p>
<p>&lt;jsp:useBean id=&#8221;shop&#8221; type=&#8221;shopping.CD&#8221; beanName=&#8221;CD&#8221; /&gt;<br />
&lt;jsp:getProperty name=&#8221;shop&#8221; property=&#8221;album&#8221; /&gt;</p>
<p>A couple of important points to note. Although you would have to name your serialized file &#8220;filename.ser&#8221;, you only indicate &#8220;filename&#8221; as the value for the beanName attribute. Also, you will have to place your serialized file within the WEB-INF\jsp\beans directory for it to be located by the JSP engine.</p>
<p><strong>Q) Can you make use of a ServletOutputStream object from within a JSP page?<br />
A)</strong> No. You are supposed to make use of only a JSPWriter object (given to you in the form of the implicit object out) for replying to clients. A JSPWriter can be viewed as a buffered version of the stream object returned by response.getWriter(), although from an implementational perspective, it is not. A page author can always disable the default buffering for any page using a page directive as:<br />
&lt;%@ page buffer=&#8221;none&#8221; %&gt;</p>
<p><strong>Q) What&#8217;s a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?<br />
A)</strong> Although the SingleThreadModel technique is easy to use, and works well for low volume sites, it does not scale well. If you anticipate your users to increase in the future, you may be better off implementing explicit synchronization for your shared data. The key however, is to effectively minimize the amount of code that is synchronzied so that you take maximum advantage of multithreading.<br />
Also, note that SingleThreadModel is pretty resource intensive from the server&#8217;s perspective. The most serious issue however is when the number of concurrent requests exhaust the servlet instance pool. In that case, all the unserviced requests are queued until something becomes free &#8211; which results in poor performance. Since the usage is non-deterministic, it may not help much even if you did add more memory and increased the size of the instance pool.<br />
<strong><br />
Q) Can I stop JSP execution while in the midst of processing a request?<br />
A)</strong> Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick (asuming Java is your scripting language) is to use the return statement when you want to terminate further processing. For example, consider:</p>
<p>&lt;% if (request.getParameter(&#8220;foo&#8221;) != null)<br />
{<br />
// generate some html or update bean property<br />
}<br />
else {</p>
<p>/* output some error message or provide redirection back to the input form after creating a memento bean updated with the &#8216;valid&#8217; form elements that were input. this bean can now be used by the previous form to initialize the input elements that were valid then, return from the body of the _jspService() method to terminate further processing */</p>
<p>return;<br />
}</p>
<p><strong>Q) How can I get to view any compilation/parsing errors at the client while developing JSP pages?<br />
A) </strong>With JSWDK 1.0, set the following servlet initialization property within the \WEB-INF\servlets.properties file for your application:<br />
jsp.initparams=sendErrToClient=true<br />
This will cause any compilation/parsing errors to be sent as part of the response to the client.</p>
<p>Q) Is there a way to reference the &#8220;this&#8221; variable within a JSP page?<br />
A) Yes, there is. Under JSP 1.0, the page implicit object is equivalent to &#8220;this&#8221;, and returns a reference to the servlet generated by the JSP page.<br />
<strong><br />
Q) How do I instantiate a bean whose constructor accepts parameters using the useBean tag?<br />
A)</strong> Consider the following bean: package bar;<br />
public class FooBean<br />
{<br />
public FooBean(SomeObj arg)<br />
{<br />
&#8230;<br />
}<br />
//getters and setters here<br />
}<br />
The only way you can instantiate this bean within your JSP page is to use a scriptlet. For example, the following snippet creates the bean with session scope:</p>
<p>&amp;l;% SomeObj x = new SomeObj(&#8230;);<br />
bar.FooBean foobar = new FooBean(x);<br />
session.putValue(&#8220;foobar&#8221;,foobar);<br />
%&gt;<br />
You can now access this bean within any other page that is part of the same session as:</p>
<p>&amp;l;%<br />
bar.FooBean foobar = session.getValue(&#8220;foobar&#8221;);<br />
%&gt;<br />
To give the bean &#8220;application scope&#8221;, you will have to place it within the ServletContext as:<br />
&amp;l;%<br />
application.setAttribute(&#8220;foobar&#8221;,foobar);<br />
%&gt;<br />
To give the bean &#8220;request scope&#8221;, you will have to place it within the request object as:<br />
&amp;l;%<br />
request.setAttribute(&#8220;foobar&#8221;,foobar);<br />
%&gt;</p>
<p>If you do not place the bean within the request, session or application scope, the bean can be accessed only within the current JSP page (page scope).<br />
Once the bean is instantiated, it can be accessed in the usual way:<br />
jsp:getProperty name=&#8221;foobar&#8221; property=&#8221;someProperty&#8221;/ jsp:setProperty name=&#8221;foobar&#8221; property=&#8221;someProperty&#8221; value=&#8221;someValue&#8221;/</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/310/" title="Hibernate Basics"><img src="Array" alt="Hibernate Basics" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/java-util-package-2/" title="JAVA UTIL PACKAGE"><img src="Array" alt="JAVA UTIL PACKAGE" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/why-does-ejb-needs-two-interfaces/" title="Why does EJB needs two interfaces"><img src="Array" alt="Why does EJB needs two interfaces" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/naming-conventions-in-java/" title="Naming Conventions in Java"><img src="Array" alt="Naming Conventions in Java" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/define-stateless-session/" title="Define Stateless Session"><img src="Array" alt="Define Stateless Session" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/jsp-interview-questions-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSP Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/jsp-interview-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/jsp-interview-questions/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 15:38:28 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Jsp Inteview Questions]]></category>
		<category><![CDATA[jsp interview questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=36</guid>
		<description><![CDATA[JSP INTERVIEW QUESTIONS AND ANSWERS Q) Briefly explain about Java Server Pages technology? A) JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content. The JSP specification, developed through an industry-wide initiative led by Sun Microsystems, defines the interaction between the server and the JSP page, and describes [...]]]></description>
			<content:encoded><![CDATA[<p><strong>JSP INTERVIEW QUESTIONS AND ANSWERS </strong><br />
<strong><br />
Q) Briefly explain about Java Server Pages technology?<br />
A)</strong> JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content. The JSP specification, developed through an industry-wide initiative led by Sun Microsystems, defines the interaction between the server and the JSP page, and describes the format and syntax of the page.</p>
<p><strong>Q) What is a JSP Page?<br />
A)</strong> A JSP page is a text document that contains two types of text: static data, which can be expressed in any text-based format (such as HTML,WML,XML,etc), and JSP elements, which construct dynamic content.JSP is a technology that lets you mix static content with dynamically-generated content.</p>
<p><strong>Q) Why do I need JSP technology if I already have servlets?<br />
A)</strong> JSP pages are compiled into servlets, so theoretically you could write servlets to support your web-based applications. However, JSP technology was designed to simplify the process of creating pages by separating web presentation from web content. In many applications, the response sent to the client is a combination of template data and dynamically-generated data. In this situation, it is much easier to work with JSP pages than to do everything with servlets.</p>
<p><strong>Q) How are the JSP requests handled?<br />
A)</strong> The following sequence of events happens on arrival of jsp request:<br />
a. Browser requests a page with .jsp file extension in webserver.<br />
b. Webserver reads the request.<br />
c. Using jsp compiler,webserver converts the jsp into a servlet class that implement the javax.servletjsp.jsp page interface.the jsp file compiles only when the page is first requested or when the jsp file has been changed.<br />
d. The generated jsp page servlet class is invoked to handle the browser request.<br />
e. The response is sent to the client by the generated servlet.<br />
<strong><br />
Q) What are the advantages of JSP?<br />
A)</strong> The following are the advantages of using JSP:<br />
a. JSP pages easily combine static templates, including HTML or XML fragments, with code that generates dynamic content.<br />
b. JSP pages are compiled dynamically into servlets when requested, so page authors can easily make updates to presentation code. JSP pages can also be precompiled if desired.<br />
c. JSP tags for invoking JavaBeans components manage these components completely, shielding the page author from the complexity of application logic.<br />
d. Developers can offer customized JSP tag libraries that page authors access using an XML-like syntax.<br />
e. Web authors can change and edit the fixed template portions of pages without affecting the application logic. Similarly, developers can make logic changes at the component level without editing the individual pages that use the logic.<br />
<strong><br />
Q) How is a JSP page invoked and compiled?<br />
A)</strong> Pages built using JSP technology are typically implemented using a translation phase that is performed once, the first time the page is called. The page is compiled into a Java Servlet class and remains in server memory, so subsequent calls to the page have very fast response times.</p>
<p><strong>Q) What are Directives?<br />
A)</strong> Directives are instructions that are processed by the JSP engine when the page is compiled to a servlet. Directives are used to set page-level instructions, insert data from external files, and specify custom tag libraries. Directives are defined between &lt; %@ and % &gt;.<br />
&lt; %@ page language==&#8221;java&#8221; imports==&#8221;java.util.*&#8221; % &gt;<br />
&lt; %@ include file==&#8221;banner.html&#8221; % &gt;</p>
<p><strong>Q) What are the different types of directives available in JSP?<br />
A)</strong> The following are the different types of directives:<br />
a. include directive : used to include a file and merges the content of the file with the current page<br />
b. page directive : used to define page specific attributes like scripting language, error page, buffer, thread safety, etc<br />
c. taglib : used to declare a custom tag library which is used in the page.</p>
<p><strong>Q) What are JSP actions?<br />
A)</strong> JSP actions are executed when a JSP page is requested. Action are inserted in the jsp page using XML syntax to control the behavior of the servlet engine. Using action, we can dynamically insert a file, reuse bean components, forward the user to another page, or generate HTML for the Java plugin. Some of the available actions are as follows:<br />
&lt;jsp:include&gt; &#8211; include a file at the time the page is requested.<br />
&lt;jsp:useBean&gt; &#8211; find or instantiate a JavaBean.<br />
&lt;jsp:setProperty&gt; &#8211; set the property of a JavaBean.<br />
&lt;jsp:getProperty&gt; &#8211; insert the property of a JavaBean into the output.<br />
&lt;jsp:forward&gt; &#8211; forward the requester to a new page.<br />
&lt;jsp:plugin&gt; &#8211; generate browser-specific code that makes an OBJECT or EMBED tag for the Java plugin.</p>
<p><strong>Q) What are Scriptlets?<br />
A)</strong> Scriptlets are blocks of programming language code (usually java) embedded within a JSP page. Scriptlet code is inserted into the servlet generated from the page. Scriptlet code is defined between &lt;% and %&gt;</p>
<p><strong>Q) What are Decalarations?<br />
A) </strong>Declarations are similar to variable declarations in Java.Variables are defined for subsequent use in expressions or scriptlets. Declarations are defined between &lt;%! and %&gt;.<br />
&lt; %! int i=0; %&gt;</p>
<p><strong>Q) How to declare instance or global variables in jsp?<br />
A)</strong> Instance variables should be declared inside the declaration part. The variables declared with JSP declaration element will be shared by all requests to the jsp page.<br />
&lt; %@ page language==&#8221;java&#8221; contentType=&#8221;text/html&#8221;% &gt;<br />
&lt; %! int i=0; %&gt;</p>
<p><strong>Q) What are Expressions?<br />
A)</strong> Expressions are variables or constants that are inserted into the data returned by the web server. Expressions are defined between &lt;% = and % &gt;<br />
&lt; %= scorer.getScore() %&gt;</p>
<p><strong>Q) What is meant by implicit objects? And what are they?<br />
A)</strong> Implicit objects are those objects which are avaiable by default. These objects are instances of classesdefined by the JSP specification. These objects could be used within the jsp page without being declared.<br />
The following are the implicit jsp objects:<br />
1. application<br />
2. page<br />
3. request<br />
4. response<br />
5. session<br />
6. exception<br />
7. out<br />
8. config<br />
9. pageContext</p>
<p><strong>Q) How do I use JavaBeans components (beans) from a JSP page?<br />
A) </strong>The JSP specification includes standard tags for bean use and manipulation. The &lt;jsp:useBean&gt; tag creates an instance of a specific JavaBean class. If the instance already exists, it is retrieved. Otherwise, a new instance of the bean is created. The &lt;jsp:setProperty&gt; and &lt;jsp:getProperty&gt; tags let you manipulate properties of a specific bean.</p>
<p><strong>Q) What is the difference between &lt;jsp:include&gt; and &lt;%@include:&gt;<br />
A)</strong> Both are used to insert files into a JSP page.<br />
&lt;%@include:&gt; is a directive which statically inserts the file at the time the JSP page is translated into a servlet.<br />
&lt;jsp:include&gt; is an action which dynamically inserts the file at the time the page is requested.</p>
<p><strong>Q) What is the difference between forward and sendRedirect?<br />
A) </strong>Both requestDispatcher.forward() and response.sendRedirect() is used to redirect to new url.<br />
forward is an internal redirection of user request within the web container to a new URL without the knowledge of the user(browser). The request object and the http headers remain intact.<br />
sendRedirect is normally an external redirection of user request outside the web container. sendRedirect sends response header back to the browser with the new URL. The browser send the request to the new URL with fresh http headers. sendRedirect is slower than forward because it involves extra server call.</p>
<p><strong>Q) Can I create XML pages using JSP technology?<br />
A)</strong> Yes, the JSP specification does support creation of XML documents. For simple XML generation, the XML tags may be included as static template portions of the JSP page. Dynamic generation of XML tags occurs through bean components or custom tags that generate XML output.</p>
<p><strong>Q) How is Java Server Pages different from Active Server Pages?<br />
A)</strong> JSP is a community driven specification whereas ASP is a similar proprietary technology from Microsoft. In JSP, the dynamic part is written in Java, not Visual Basic or other MS-specific language. JSP is portable to other operating systems and non-Microsoft Web servers whereas it is not possible with ASP</p>
<p><strong>Q) Can&#8217;t Javascript be used to generate dynamic content rather than JSP?<br />
A)</strong> JavaScript can be used to generate dynamic content on the client browser. But it can handle only handles situations where the dynamic information is based on the client&#8217;s environment. It will not able to harness server side information directly.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/benefits-of-connection-pooling/" title="Benefits of Connection Pooling"><img src="Array" alt="Benefits of Connection Pooling" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/main-exceptions-in-thread/" title="Main Exceptions in Thread"><img src="Array" alt="Main Exceptions in Thread" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/explain-java-comments/" title="Explain Java Comments"><img src="Array" alt="Explain Java Comments" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/can-we-provide-a-constructor-in-the-servlet-class/" title="Can we provide a constructor in the servlet class"><img src="Array" alt="Can we provide a constructor in the servlet class" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/creating-a-sessionfactory-using-hibernate/" title="Creating a SessionFactory Using Hibernate"><img src="Array" alt="Creating a SessionFactory Using Hibernate" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/jsp-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
