<?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>StudyJava.org &#187; EJB</title>
	<atom:link href="http://studyjava.org/category/ejb/feed" rel="self" type="application/rss+xml" />
	<link>http://studyjava.org</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 05 Apr 2010 11:49:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Display the contents of a Zip file using java</title>
		<link>http://studyjava.org/ejb/display-the-contents-of-a-zip-file-using-java</link>
		<comments>http://studyjava.org/ejb/display-the-contents-of-a-zip-file-using-java#comments</comments>
		<pubDate>Thu, 18 Mar 2010 17:35:06 +0000</pubDate>
		<dc:creator>rathi</dc:creator>
				<category><![CDATA[EJB]]></category>
		<category><![CDATA[java zip]]></category>
		<category><![CDATA[zip in java]]></category>

		<guid isPermaLink="false">http://studyjava.org/?p=461</guid>
		<description><![CDATA[package com.org.servlet; import java.io.*; import java.util.zip.*; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ZipView extends HttpServlet { /** * Display the contents of a zip file */ private static final long serialVersionUID = 1L; public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { try { String zipFile = request.getParameter(&#8220;fileNames&#8221;);//specify the zip file [...]]]></description>
			<content:encoded><![CDATA[<p>package com.org.servlet;</p>
<p>import java.io.*;</p>
<p>import java.util.zip.*;</p>
<p>import javax.servlet.ServletException;</p>
<p>import javax.servlet.http.HttpServlet;</p>
<p>import javax.servlet.http.HttpServletRequest;</p>
<p>import javax.servlet.http.HttpServletResponse;</p>
<p>public class ZipView extends HttpServlet</p>
<p>{</p>
<p>/**</p>
<p>* Display the contents of a zip file</p>
<p>*/</p>
<p>private static final long serialVersionUID = 1L;</p>
<p>public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException</p>
<p>{</p>
<p>try</p>
<p>{</p>
<p>String zipFile = request.getParameter(&#8220;fileNames&#8221;);//specify the zip file</p>
<p>response.setContentType(&#8220;text/html&#8221;);</p>
<p>PrintWriter out = response.getWriter();</p>
<p>out.println(&#8220;&lt;table&gt;&lt;tr&gt;&lt;th&gt;File Name&lt;/th&gt;&lt;th&gt;Size&lt;/th&gt;&lt;th&gt;Date &lt;/th&gt;&lt;th&gt;Compressed Size&lt;/th&gt;&lt;/tr&gt;&#8221;);</p>
<p>if(zipFile != null &amp;&amp; zipFile.trim().length()&gt;0){</p>
<p>//BufferedOutputStream out = null;</p>
<p>ZipInputStream  in = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));</p>
<p>ZipEntry entry;</p>
<p>while((entry = in.getNextEntry()) != null)</p>
<p>{                    out.println(&#8220;&lt;tr&gt;&lt;td&gt;&#8221;+ entry.getName()+&#8221;&lt;/td&gt;&lt;td&gt;&#8221;+ entry.getSize()+&#8221;&lt;/td&gt;&lt;td&gt;&#8221;+ entry.getTime() +&#8221; &lt;/td&gt;&lt;td&gt;&#8221;+ entry.getCompressedSize() +&#8221; &lt;/td&gt;&lt;/tr&gt;&#8221;);</p>
<p>int count;</p>
<p>byte data[] = new byte[1000];</p>
<p>out = new BufferedOutputStream(new FileOutputStream(&#8220;C:/pdf/out.txt&#8221;),1000);</p>
<p>while ((count = in.read(data,0,1000)) != -1)</p>
<p>{</p>
<p>out.write(data,0,count);</p>
<p>}</p>
<p>out.flush();</p>
<p>out.close();</p>
<p>*/</p>
<p>}</p>
<p>}</p>
<p>out.println(&#8220;&lt;/table&gt;&#8221;);</p>
<p>out.flush();</p>
<p>out.close();</p>
<p>}</p>
<p>catch(Exception e)</p>
<p>{</p>
<p>e.printStackTrace();</p>
<p>}</p>
<p>}</p>
<p>public void doGet(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException {</p>
<p>doPost(request, response);</p>
<p>}</p>
<p>}</p>
<div id="st0000000001" class="st-taf"><script src="http://taf.socialtwist.com:80/taf/js/shoppr.core.js?id=0000000001"></script><img style="border:0;margin:0;padding:0;" src="http://tellafriend.socialtwist.com:80/wizard/images/tafbutton_blue16.png" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '0000000001', 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fdisplay-the-contents-of-a-zip-file-using-java', 'Display+the+contents+of+a+Zip+file+using+java')" onclick="cw(this, {id:'0000000001',link: 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fdisplay-the-contents-of-a-zip-file-using-java', title: '+Display+the+contents+of+a+Zip+file+using+java+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://studyjava.org/ejb/display-the-contents-of-a-zip-file-using-java/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Display or download Files using servlet</title>
		<link>http://studyjava.org/ejb/display-or-download-files-using-servlet</link>
		<comments>http://studyjava.org/ejb/display-or-download-files-using-servlet#comments</comments>
		<pubDate>Thu, 18 Mar 2010 13:54:34 +0000</pubDate>
		<dc:creator>rathi</dc:creator>
				<category><![CDATA[EJB]]></category>
		<category><![CDATA[Display or download Files using servlet]]></category>
		<category><![CDATA[Display using servlet]]></category>
		<category><![CDATA[download Files]]></category>
		<category><![CDATA[using servlet]]></category>

		<guid isPermaLink="false">http://studyjava.org/?p=466</guid>
		<description><![CDATA[import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * @author name * This servlet class is used to display or download the file * */ public class DownloadFile extends HttpServlet{ /** * */ private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, [...]]]></description>
			<content:encoded><![CDATA[<p>import java.io.File;</p>
<p>import java.io.FileInputStream;</p>
<p>import java.io.IOException;</p>
<p>import java.io.InputStream;</p>
<p>import javax.servlet.ServletException;</p>
<p>import javax.servlet.ServletOutputStream;</p>
<p>import javax.servlet.http.HttpServlet;</p>
<p>import javax.servlet.http.HttpServletRequest;</p>
<p>import javax.servlet.http.HttpServletResponse;</p>
<p>/**</p>
<p>* @author name</p>
<p>* This servlet class is used to display or download the file</p>
<p>*</p>
<p>*/</p>
<p>public class DownloadFile extends HttpServlet{</p>
<p>/**</p>
<p>*</p>
<p>*/</p>
<p>private static final long serialVersionUID = 1L;</p>
<p>public void doGet(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException {</p>
<p>doPost(request, response);</p>
<p>}</p>
<p>public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {</p>
<p>ServletOutputStream outputStream = null;</p>
<p>InputStream input = null;</p>
<p>try {</p>
<p>outputStream = response.getOutputStream();</p>
<p>String filePath = request.getParameter(&#8220;fileNames&#8221;);  //filepath</p>
<p>if(filePath != null &amp;&amp; filePath.trim().length()&gt;0){</p>
<p>String download = request.getParameter(&#8220;download&#8221;);//download or display</p>
<p>File prefile = new File(filePath);</p>
<p>byte buff[] = new byte[8192];</p>
<p>input = new FileInputStream(prefile);</p>
<p>String contenttype = filePath.substring(filePath.lastIndexOf(&#8220;.&#8221;)+1, filePath.length());</p>
<p>contenttype = contenttype.toLowerCase();</p>
<p>if(download != null &amp;&amp; download.trim().length()&gt;0){</p>
<p>response.setContentType(&#8220;application/octet-stream&#8221;);</p>
<p>}</p>
<p>else{</p>
<p>if (contenttype != null) {</p>
<p>String responseType = getResponseContentType(contenttype);</p>
<p>response.setContentType(responseType);</p>
<p>} else {</p>
<p>response.setContentType(&#8220;application/octet-stream&#8221;);</p>
<p>}</p>
<p>}</p>
<p>response.setHeader(&#8220;Content-Length&#8221;, String.valueOf(prefile.length()));</p>
<p>if(download != null &amp;&amp; download.trim().length()&gt;0){</p>
<p>response.setHeader(&#8220;Content-Disposition&#8221;,&#8221;attachment; filename=\&#8221;"+ prefile.getName()+&#8221;\&#8221;");</p>
<p>}</p>
<p>else{</p>
<p>response.setHeader(&#8220;Content-disposition&#8221;, (new StringBuilder(&#8220;inline; filename=&#8221;)).append(prefile.getName()).toString());</p>
<p>}</p>
<p>response.addHeader(&#8220;Cache-Control&#8221;, &#8220;no-transform, max-age=0&#8243;);</p>
<p>int i = 0;</p>
<p>while ((i = input.read(buff)) &gt; 0) {</p>
<p>outputStream.write(buff, 0, i);</p>
<p>outputStream.flush();</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>catch (Exception e) {</p>
<p>e.printStackTrace();</p>
<p>}</p>
<p>finally {</p>
<p>if (input != null)</p>
<p>input.close();</p>
<p>if (outputStream != null)</p>
<p>outputStream.close();</p>
<p>}</p>
<p>}</p>
<p>private String getResponseContentType(String contenttype){</p>
<p>String responseType = &#8220;&#8221;;</p>
<p>if(contenttype.indexOf(&#8220;doc&#8221;)&gt;-1){</p>
<p>responseType = &#8220;application/vnd.ms-word&#8221;;</p>
<p>}</p>
<p>if(contenttype.indexOf(&#8220;rtf&#8221;)&gt;-1){</p>
<p>responseType = &#8220;application/rtf&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;xls&#8221;)&gt;-1){</p>
<p>responseType = &#8220;application/vnd.ms-excel&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;ppt&#8221;)&gt;-1){</p>
<p>responseType = &#8220;application/ppt&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;xml&#8221;)&gt;-1){</p>
<p>responseType = &#8220;text/xml&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;html&#8221;)&gt;-1){</p>
<p>responseType = &#8220;text/html&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;htm&#8221;)&gt;-1){</p>
<p>responseType = &#8220;text/htm&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;txt&#8221;)&gt;-1 || contenttype.indexOf(&#8220;log&#8221;)&gt;-1){</p>
<p>responseType = &#8220;text/plain&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;pdf&#8221;)&gt;-1){</p>
<p>responseType = &#8220;application/pdf&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;gif&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/gif&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;png&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/png&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;jpg&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/jpg&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;jpeg&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/JPEG&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;jpe&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/JPEG&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;bmp&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/bmp&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;jpeg&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/JPEG&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;tiff&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/tiff&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;tif&#8221;)&gt;-1){</p>
<p>responseType = &#8220;image/tiff&#8221;;</p>
<p>}</p>
<p>else if(contenttype.indexOf(&#8220;html&#8221;)&gt;-1){</p>
<p>responseType = &#8220;text/html&#8221;;</p>
<p>}</p>
<p>else{</p>
<p>responseType = &#8220;application/octet-stream&#8221;;</p>
<p>}</p>
<p>return responseType;</p>
<p>}</p>
<p>}</p>
<p><strong>Configuration in web.xml</strong></p>
<p>&lt;servlet&gt;</p>
<p>&lt;servlet-name&gt;ViewFile&lt;/servlet-name&gt;</p>
<p>&lt;servlet-class&gt;com.org.servlet.DownloadFile&lt;/servlet-class&gt;</p>
<p>&lt;/servlet&gt;</p>
<p>&lt;servlet-mapping&gt;</p>
<p>&lt;servlet-name&gt;ViewFile&lt;/servlet-name&gt;</p>
<p>&lt;url-pattern&gt;*.viewfile&lt;/url-pattern&gt;</p>
<p>&lt;/servlet-mapping&gt;</p>
<p>&lt;mime-mapping&gt;</p>
<p>&lt;extension&gt;pptx&lt;/extension&gt;</p>
<p>&lt;mime-type&gt;</p>
<p>application/vnd.openxmlformats-officedocument.presentationml.presentation</p>
<p>&lt;/mime-type&gt;</p>
<p>&lt;/mime-mapping&gt;</p>
<p>&lt;mime-mapping&gt;</p>
<p>&lt;extension&gt;docx&lt;/extension&gt;</p>
<p>&lt;mime-type&gt;application/vnd.openxmlformats-officedocument.wordprocessingml.document&lt;/mime-type&gt;</p>
<p>&lt;/mime-mapping&gt;</p>
<p>&lt;mime-mapping&gt;</p>
<p>&lt;extension&gt;xlsx&lt;/extension&gt;</p>
<p>&lt;mime-type&gt;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&lt;/mime-type&gt;</p>
<p>&lt;/mime-mapping&gt;</p>
<p><strong>JSP Code&#8230;&#8230;</strong></p>
<p>&lt;form name=&#8217;form1&#8242; method=&#8221;post&#8221; action=&#8221;file.viewfile&#8221; target=&#8221;fileframe&#8221;/&gt;</p>
<p>&lt;input type=&#8217;hidden&#8217; name=&#8217;fileNames&#8217; id=&#8217;fileNames&#8217; value=&#8217;C:/path/resume.txt&#8217;/&gt;</p>
<p>&lt;input type=&#8217;hidden&#8217; name=&#8217;download&#8217; id=&#8217;download&#8217; value=&#8217;true&#8217;/&gt;//set as blank when u want to display</p>
<p>&lt;input type=&#8217;Submit&#8217; name=&#8217;Submit&#8217; id=&#8217;Submit&#8217; value=&#8217;Display&#8217;/&gt;</p>
<p>&lt;/form&gt;</p>
<p>&lt;frame&gt;&lt;/frame&gt;</p>
<div id="st0000000001" class="st-taf"><script src="http://taf.socialtwist.com:80/taf/js/shoppr.core.js?id=0000000001"></script><img style="border:0;margin:0;padding:0;" src="http://tellafriend.socialtwist.com:80/wizard/images/tafbutton_blue16.png" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '0000000001', 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fdisplay-or-download-files-using-servlet', 'Display+or+download+Files+using+servlet')" onclick="cw(this, {id:'0000000001',link: 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fdisplay-or-download-files-using-servlet', title: '+Display+or+download+Files+using+servlet+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://studyjava.org/ejb/display-or-download-files-using-servlet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to override browser cookie from java servlet.</title>
		<link>http://studyjava.org/ejb/how-to-override-browser-cookie-from-java-servlet</link>
		<comments>http://studyjava.org/ejb/how-to-override-browser-cookie-from-java-servlet#comments</comments>
		<pubDate>Fri, 26 Feb 2010 16:37:31 +0000</pubDate>
		<dc:creator>rathi</dc:creator>
				<category><![CDATA[EJB]]></category>
		<category><![CDATA[override browser cookie]]></category>

		<guid isPermaLink="false">http://studyjava.org/?p=433</guid>
		<description><![CDATA[we can override browser cookie using this code. response.setHeader(&#8220;p3p&#8221;, &#8220;CP=IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT&#8221;);]]></description>
			<content:encoded><![CDATA[<p>we can override browser cookie using this code.</p>
<p>response.setHeader(&#8220;p3p&#8221;, &#8220;CP=IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT&#8221;);</p>
<div id="st0000000001" class="st-taf"><script src="http://taf.socialtwist.com:80/taf/js/shoppr.core.js?id=0000000001"></script><img style="border:0;margin:0;padding:0;" src="http://tellafriend.socialtwist.com:80/wizard/images/tafbutton_blue16.png" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '0000000001', 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fhow-to-override-browser-cookie-from-java-servlet', 'how+to+override+browser+cookie+from+java+servlet.')" onclick="cw(this, {id:'0000000001',link: 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fhow-to-override-browser-cookie-from-java-servlet', title: '+how+to+override+browser+cookie+from+java+servlet.+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://studyjava.org/ejb/how-to-override-browser-cookie-from-java-servlet/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Applet</title>
		<link>http://studyjava.org/ejb/java-applet</link>
		<comments>http://studyjava.org/ejb/java-applet#comments</comments>
		<pubDate>Tue, 15 Sep 2009 03:10:17 +0000</pubDate>
		<dc:creator>rathi</dc:creator>
				<category><![CDATA[EJB]]></category>
		<category><![CDATA[Java Applet:]]></category>

		<guid isPermaLink="false">http://studyjava.org/?p=178</guid>
		<description><![CDATA[Java Applet: An applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. Java applets were introduced in the first version of the Java language in 1995. An applet is typically embedded inside a web-page and runs in the context of the browser. [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left"><strong>Java Applet:</strong></p>
<p style="text-align: left"><strong> </strong></p>
<div id="attachment_201" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-201" title="java_applet" src="http://studyjava.org/wp-content/uploads/2009/09/java_applet-300x247.png" alt="java" width="300" height="247" /><p class="wp-caption-text">java</p></div>
<p style="text-align: left">An applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. Java applets were introduced in the first version of the Java language in 1995. An applet is typically embedded inside a web-page and runs in the context of the browser. An applet must be a subclass of the java.applet.Applet class, which provides the standard interface between the applet and the browser environment. Java applets are executed in a sandbox by most web browsers, preventing them from accessing local data. A Java applet extends the class java.applet.Applet, or in the case of a Swing applet, javax.swing.JApplet. The class must override methods from the applet class to set up a user interface inside itself. Java applets can run in a Web browser using a Java Virtual Machine or in Sun&#8217;s AppletViewer, a stand-alone tool for testing applets.</p>
<p><strong>Life Cycle of an Applet</strong>: Basically, there are four methods in the Applet class on which any applet is built.</p>
<p><strong>init</strong>: This method is intended for whatever initialization is needed for your applet. It is called after the param attributes of the applet tag.</p>
<p style="text-align: left"><strong>start</strong>: This method is automatically called after init method. It is also called whenever user returns to the page containing the applet after visiting other pages.</p>
<p style="text-align: left"><strong>stop:</strong> This method is automatically called whenever the user moves away from the page containing applets. You can use this method to stop an animation.</p>
<p style="text-align: left"><strong>destroy</strong>: This method is only called when the browser shuts down normally.</p>
<p>Java applets can be executed by browsers for many platforms, including Windows, Unix, Mac OS and Linux. It is also trivial to run Java applet as an application with very little extra code. This has the advantage of running a Java applet in offline mode without the need for internet browser software and also directly from the development IDE.</p>
<p>The API is provided by the javax.swing.JApplet class and the java.applet.AppletContext interface.</p>
<p>Applets can use these APIs to do the following:</p>
<ul>
<li>Be notified by the browser of milestones.</li>
<li>Load data files specified relative to the URL of the applet or the page in which it is running.</li>
<li>Display short status strings.</li>
<li>Make the browser display a document.</li>
<li>Find other applets running in the same page.</li>
<li>Play sounds.</li>
<li>Get parameters specified by the user in the &lt;APPLET&gt; tag.</li>
</ul>
<p style="text-align: left"><strong>Example of a simple APPLET tag:<br />
</strong></p>
<p>&lt;applet code=&#8221;MyApplet.class&#8221; width=100 height=140&gt;&lt;/applet&gt;</p>
<p>This tells the viewer or browser to load the applet whose compiled code is in MyApplet.class (in the same directory as the current HTML document), and to set the initial size of the applet to 100 pixels wide and 140 pixels high.</p>
<p><strong>Complex example of an APPLET tag: </strong></p>
<p>&lt;applet codebase=&#8221;http://java.sun.com/applets/NervousText/1.1&#8243;<br />
code=&#8221;NervousText.class&#8221; width=400 height=75&gt;<br />
&lt;param name=&#8221;text&#8221; value=&#8221;Welcome to HotJava!&#8221;&gt;<br />
&lt;hr&gt;<br />
If you were using a Java-enabled browser such as HotJava,<br />
you would see dancing text instead of this paragraph.<br />
&lt;hr&gt;<br />
&lt;/applet&gt;</p>
<p>This tells the viewer or browser to load the applet whose compiled code is at the URL http://java.sun.com/applets/NervousText/1.1/NervousText.class, to set the initial size of the applet to 400&#215;75 pixels. The viewer/browser must also set the applet&#8217;s &#8220;text&#8221; attribute (which customizes the text this applet displays) to be &#8220;Welcome to HotJava!&#8221; If the page is viewed by a browser that can&#8217;t execute Java applets, then the browser will ignore the APPLET and PARAM tags, displaying only the HTML between the &lt;param&gt; and &lt;/applet&gt; tags (the alternate HTML).</p>
<p><strong>Advantages of Java Applet:</strong></p>
<ul>
<li>Java Applet simple to make it work on Linux, Windows and Mac OS i.e. to make it cross platform</li>
<li>Same applet can work on &#8220;all&#8221; installed versions of Java at the same time, rather than just the latest plug-in version only. However, if an applet requires a later version of the JRE the client will be forced to wait during the large download.</li>
<li>java Applet supported by most web browsers</li>
<li>Java Applet will cache in most web browsers, so will be quick to load when returning to a web page but may get stuck in the cache and have issues when new versions come out.</li>
<li>Applet can have full access to the machine it is running on if the user agrees</li>
<li>Applet can improve with use: after a first applet is run, the JVM is already running and starts quickly, benefitting regular users of Java but the JVM will need to restart each time the browser starts fresh.</li>
<li>Applet can run at a speed that is comparable to (but generally slower than) other compiled languages such as C++, but many times faster than JavaScript</li>
<li>Applet can move the work from the server to the client, making a web solution more scalable with the number of users/clients developers can develop and debug an applet direct simply by creating a main routine (either in the applet&#8217;s class or in a separate class) and call init() and start() on the applet, thus allowing for development in their favorite J2SE development environment. All one has to do after that is re-test the applet in the appletviewer program or a web browser to ensure it conforms to security restrictions.</li>
<li>an untrusted applet has no access to the local machine and can only access the server it came from. This makes such applet much safer to run than standalone executable that it could replace.</li>
</ul>
<p style="text-align: left"><strong>Disadvantages of Java Applet:</strong></p>
<ul>
<li>Java Applet requires the Java plug-in, which is not available by default on all web browsers.</li>
<li>Prior to version 6u12, Sun did not provide a 64-bit version of its Java plug-in, forcing users to use the 32-bit plugin with a 32-bit browser.</li>
<li>Java Applet cannot start until the Java Virtual Machine is running, and this may have significant startup time the first time it is used.</li>
<li>Some organizations only allow software installed by the administrators. As a result, many users cannot view applets by default.</li>
</ul>
<div style="overflow: hidden; width: 1px; height: 1px;">An applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. Java applets were introduced</p>
<p>in the first version of the Java language in 1995. An applet is typically embedded inside a web-page and runs in the context of the browser. An applet must</p>
<p>be a subclass of the java.applet.Applet class, which provides the standard interface between the applet and the browser environment. Java applets are</p>
<p>executed in a sandbox by most web browsers, preventing them from accessing local data. A Java applet extends the class java.applet.Applet, or in the case of</p>
<p>a Swing applet, javax.swing.JApplet. The class must override methods from the applet class to set up a user interface inside itself. Java applets can run in</p>
<p>a Web browser using a Java Virtual Machine or in Sun&#8217;s AppletViewer, a stand-alone tool for testing applets.</p>
<p>Life Cycle of an Applet: Basically, there are four methods in the Applet class on which any applet is built.</p>
<p>init: This method is intended for whatever initialization is needed for your applet. It is called after the param attributes of the applet tag.<br />
start: This method is automatically called after init method. It is also called whenever user returns to the page containing the applet after visiting other</p>
<p>pages.<br />
stop: This method is automatically called whenever the user moves away from the page containing applets. You can use this method to stop an animation.<br />
destroy: This method is only called when the browser shuts down normally.</p>
<p>Java applets can be executed by browsers for many platforms, including Windows, Unix, Mac OS and Linux. It is also trivial to run Java applet as an</p>
<p>application with very little extra code. This has the advantage of running a Java applet in offline mode without the need for internet browser software and</p>
<p>also directly from the development IDE.</p>
<p>The API is provided by the javax.swing.JApplet class and the java.applet.AppletContext interface.</p>
<p>Applets can use these APIs to do the following:</p>
<p>Be notified by the browser of milestones.<br />
Load data files specified relative to the URL of the applet or the page in which it is running.<br />
Display short status strings.<br />
Make the browser display a document.<br />
Find other applets running in the same page.<br />
Play sounds.<br />
Get parameters specified by the user in the &lt;APPLET&gt; tag.</p>
<p>example of a simple APPLET tag:</p>
<p>&lt;applet code=&#8221;MyApplet.class&#8221; width=100 height=140&gt;&lt;/applet&gt;</p>
<p>This tells the viewer or browser to load the applet whose compiled code is in MyApplet.class (in the same directory as the current HTML document), and to set</p>
<p>the initial size of the applet to 100 pixels wide and 140 pixels high.</p>
<p>complex example of an APPLET tag:</p>
<p>&lt;applet codebase=&#8221;http://java.sun.com/applets/NervousText/1.1&#8243;<br />
code=&#8221;NervousText.class&#8221; width=400 height=75&gt;<br />
&lt;param name=&#8221;text&#8221; value=&#8221;Welcome to HotJava!&#8221;&gt;<br />
&lt;hr&gt;<br />
If you were using a Java-enabled browser such as HotJava,<br />
you would see dancing text instead of this paragraph.<br />
&lt;hr&gt;<br />
&lt;/applet&gt;</p>
<p>This tells the viewer or browser to load the applet whose compiled code is at the URL http://java.sun.com/applets/NervousText/1.1/NervousText.class, to set</p>
<p>the initial size of the applet to 400&#215;75 pixels. The viewer/browser must also set the applet&#8217;s &#8220;text&#8221; attribute (which customizes the text this applet</p>
<p>displays) to be &#8220;Welcome to HotJava!&#8221; If the page is viewed by a browser that can&#8217;t execute Java applets, then the browser will ignore the APPLET and PARAM</p>
<p>tags, displaying only the HTML between the &lt;param&gt; and &lt;/applet&gt; tags (the alternate HTML).</p>
<p>Advantages:</p>
<p>Java Applet simple to make it work on Linux, Windows and Mac OS i.e. to make it cross platform<br />
Same applet can work on &#8220;all&#8221; installed versions of Java at the same time, rather than just the latest plug-in version only. However, if an applet</p>
<p>requires a later version of the JRE the client will be forced to wait during the large download.<br />
java Applet supported by most web browsers<br />
Java Applet will cache in most web browsers, so will be quick to load when returning to a web page but may get stuck in the cache and have issues when new versions</p>
<p>come out.<br />
Applet can have full access to the machine it is running on if the user agrees<br />
Applet can improve with use: after a first applet is run, the JVM is already running and starts quickly, benefitting regular users of Java but the JVM will need</p>
<p>to restart each time the browser starts fresh.<br />
Applet can run at a speed that is comparable to (but generally slower than) other compiled languages such as C++, but many times faster than JavaScript<br />
Applet can move the work from the server to the client, making a web solution more scalable with the number of users/clients<br />
developers can develop and debug an applet direct simply by creating a main routine (either in the applet&#8217;s class or in a separate class) and call init() and</p>
<p>start() on the applet, thus allowing for development in their favorite J2SE development environment. All one has to do after that is re-test the applet in</p>
<p>the appletviewer program or a web browser to ensure it conforms to security restrictions.<br />
an untrusted applet has no access to the local machine and can only access the server it came from. This makes such applet much safer to run than standalone</p>
<p>executable that it could replace.</p>
<p>Disadvantages:</p>
<p>Java Applet requires the Java plug-in, which is not available by default on all web browsers.<br />
Prior to version 6u12, Sun did not provide a 64-bit version of its Java plug-in, forcing users to use the 32-bit plugin with a 32-bit browser.<br />
Java Applet cannot start until the Java Virtual Machine is running, and this may have significant startup time the first time it is used.<br />
Some organizations only allow software installed by the administrators. As a result, many users cannot view applets by default.</p></div>
<div id="st0000000001" class="st-taf"><script src="http://taf.socialtwist.com:80/taf/js/shoppr.core.js?id=0000000001"></script><img style="border:0;margin:0;padding:0;" src="http://tellafriend.socialtwist.com:80/wizard/images/tafbutton_blue16.png" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '0000000001', 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fjava-applet', 'Java+Applet')" onclick="cw(this, {id:'0000000001',link: 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fjava-applet', title: '+Java+Applet+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://studyjava.org/ejb/java-applet/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Entity Beans Overview</title>
		<link>http://studyjava.org/ejb/entity-beans-overview</link>
		<comments>http://studyjava.org/ejb/entity-beans-overview#comments</comments>
		<pubDate>Sun, 28 Jun 2009 17:19:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[EJB]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java beans.  ejb]]></category>

		<guid isPermaLink="false">http://studyjava.org/?p=25</guid>
		<description><![CDATA[Entity Beans Overview Java programmers are already familiar with objects.  An entity bean is an object with special properties: It is permanent. Standard Java objects come into existence when they are created in a program.  When the program terminates, the object is lost.  But an entity bean stays around until it is deleted.  A program [...]]]></description>
			<content:encoded><![CDATA[<h3>Entity Beans Overview</h3>
<p>Java programmers are already familiar with objects.  An entity bean is an object with special properties:</p>
<p><img class="alignleft size-medium wp-image-26" title="ejb" src="http://studyjava.org/wp-content/uploads/2009/06/ejb-300x164.gif" alt="ejb" width="300" height="164" /></p>
<p><strong>It is permanent.</strong> Standard Java objects come into existence when they are created in a program.  When the program terminates, the object is lost.  But an entity bean stays around until it is deleted.  A program can create an entity bean, then the program can be stopped and restarted.  The entity bean will continue to exist.  After being restarted, the program can again find the entity bean it was working with, and continue using the same entity bean.</p>
<p>In practice, entity beans need to be backed up by some kind of permanent storage, typically a database.</p>
<p><strong>It is executed remotely</strong>.  Methods of an entity bean run on a &#8220;server&#8221; machine.  When you call an entity bean&#8217;s method, your program&#8217;s thread stops executing and control passes over to the server.  When the method returns from the server, the local thread resumes executing.</p>
<p><strong>It is identified by a primary key.</strong> Entity Beans must have a primary key.  The primary key is unique &#8212; each entity bean is uniquely identified by its primary key.  For example, an &#8220;employee&#8221; entity bean may have Social Security numbers as primary keys.  You can only use entity beans when your objects have a unique identifier field, or when you can add such a field.</p>
<h3>Session Beans</h3>
<p>Session beans are different from entity beans in that they are not permanent objects.  They are also not shareable in general, though it is possible to share them by using their &#8220;handles&#8221;.</p>
<p>Session beans can be used to distribute and isloate processing tasks, somewhat analogous to the way each Java class can be used to encapsulate a type of related processing.  Each session bean can be used to perform a certain task on behalf of its client.  The tasks can be distributed on different machines.</p>
<p>Another way session beans can be thought of, is like how browsers and web-servers operate.  A web-server is located in a particular location, but multiple browsers can connect to it and get it to perform services (such as delivering HTML pages) on their behalf.  Each server performs a specialized unique task The clients can connect to any of a number of servers, depending upon their needs.</p>
<p>In the same way, each session bean may perform a type of task, at a given remote location.  Its clients will be other Java programs (rather than a browser).  Its clients will connect to it when they need that type of task done.  The tasks will be usually be programmatic and more specific than &#8220;give me this HTML page&#8221;.  An example might be a session bean that performs a specialized calculation that is secret from the clients.  The clients do not need to know how to do the calculation, but just need to know the results.  The session bean might provide methods for providing the input of the calculation and for getting the result of the calculation.  The client just needs to access the session bean and call its methods.  Another example may be when the book-keeping needs to be done in a central location.  For instance, a bank&#8217;s ATM machines may be Java programs that are clients of a session bean running in a central location and that does the book-keeping tasks of maintaining the balance in the account, reducing the amount for each ATM withdrawal and increasing it for each ATM deposit etc.</p>
<p>Session beans do not have a primary key.  Unlike entity beans, session beans are not primarily meant to be shared or found later (though they can be.)  Therefore two session beans may have the same fields and still be two different objects.</p>
<h3>The EJB interfaces</h3>
<p>Each EJB provides some interfaces that its clients use to work with the EJB.</p>
<h4>Remote Interface</h4>
<p>The <tt>remote</tt> interface is the business end of the EJB.  This is the set of actual services provides by the EJB.</p>
<h4>Home Interface</h4>
<p>The <tt>home</tt> interface is the book-keeping interface.  It helps clients create a new instance of an EJB, or to find an existing instance of an EJB.  The methods used to find existing EJBs are known as &#8220;<tt>finder</tt>&#8221; methods.  Since session beans are not designed to be shareable, there are no session bean finder methods.</p>
<h4>Implementation</h4>
<p>The <tt>home</tt> interface doesn&#8217;t actually need an implementation!  This is because its tasks are straightforward enough that the EJB container can automatically provide the implementation.</p>
<p>The <tt>remote</tt> interface, however, needs an implementation which is supplied by the EJB program</p>
<p><strong>It is network based.</strong> Standard Java objects are used only by one program.</p>
<div id="st0000000001" class="st-taf"><script src="http://taf.socialtwist.com:80/taf/js/shoppr.core.js?id=0000000001"></script><img style="border:0;margin:0;padding:0;" src="http://tellafriend.socialtwist.com:80/wizard/images/tafbutton_blue16.png" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '0000000001', 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fentity-beans-overview', 'Entity+Beans+Overview')" onclick="cw(this, {id:'0000000001',link: 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fentity-beans-overview', title: '+Entity+Beans+Overview+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://studyjava.org/ejb/entity-beans-overview/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mastering Enterprise JavaBeans</title>
		<link>http://studyjava.org/ejb/mastering-enterprise-javabeans</link>
		<comments>http://studyjava.org/ejb/mastering-enterprise-javabeans#comments</comments>
		<pubDate>Sun, 28 Jun 2009 16:49:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[EJB]]></category>

		<guid isPermaLink="false">http://studyjava.org/?p=17</guid>
		<description><![CDATA[Third Edition Published in January 2005, the best-selling book Mastering EJB is now in its third edition and has been updated for EJB2.1 and also features new chapters on security and Web services integration. The book is about EJB concepts, methodology and development. This book also contains a number of advanced EJB topics, giving you [...]]]></description>
			<content:encoded><![CDATA[<h1 style="text-decoration: none; margin-top: 0px; margin-bottom: 0px; font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif; font-size: 22px; color: #284b78; font-weight: bold;"><img class="alignleft size-full wp-image-18" title="ejb" src="http://studyjava.org/wp-content/uploads/2009/06/ejb.jpg" alt="ejb" width="229" height="283" /> Third Edition</h1>
<p style="margin-top: 2px;">Published in January 2005, the best-selling book Mastering EJB is now in its third edition and has been updated for EJB2.1 and also features new chapters on security and Web services integration. The book is about EJB concepts, methodology and development. This book also contains a number of advanced EJB topics, giving you a practical and real�world understanding of the subject. By reading this book, you will acquire a deep understanding of EJB.</p>
<h2 style="text-decoration: none; margin-top: 0px; margin-bottom: 0px; font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, sans-serif; font-size: 16px; color: #284b78; font-weight: bold;">What you will find here</h2>
<p style="margin-top: 2px;">This is the official homepage for Mastering EJB Third Edition. Here you can download the entire book in PDF format for free, and you will also find the source code for the book.</p>
<div id="st0000000001" class="st-taf"><script src="http://taf.socialtwist.com:80/taf/js/shoppr.core.js?id=0000000001"></script><img style="border:0;margin:0;padding:0;" src="http://tellafriend.socialtwist.com:80/wizard/images/tafbutton_blue16.png" onmouseout="hideHoverMap(this)" onmouseover="showHoverMap(this, '0000000001', 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fmastering-enterprise-javabeans', 'Mastering+Enterprise+JavaBeans')" onclick="cw(this, {id:'0000000001',link: 'http%3A%2F%2Fstudyjava.org%2Fejb%2Fmastering-enterprise-javabeans', title: '+Mastering+Enterprise+JavaBeans+' })"/></div>]]></content:encoded>
			<wfw:commentRss>http://studyjava.org/ejb/mastering-enterprise-javabeans/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

