<?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>Fouad&#039;s Blog &#187; JEE</title>
	<atom:link href="http://www.fouad-saidy.com/archives/category/jee/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fouad-saidy.com</link>
	<description>Select * From World where type=&#34;computing&#34;;</description>
	<lastBuildDate>Thu, 17 Mar 2011 14:20:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Step By Step Create Simple Calculator using Eclipse Galileo &amp;  EJB 3.0</title>
		<link>http://www.fouad-saidy.com/archives/12</link>
		<comments>http://www.fouad-saidy.com/archives/12#comments</comments>
		<pubDate>Sat, 30 Jan 2010 12:41:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[EJB]]></category>
		<category><![CDATA[JEE]]></category>

		<guid isPermaLink="false">http://fouad-saidy.freehostia.com/?p=12</guid>
		<description><![CDATA[



Remark:

I received many emails that talk about the error of  &#8220;Firstcalc not bound&#8221;  the problem that if you didn&#8217;t referenced the EJB project in the web application your server can not know the calcImpl class for this reason it shows this error.
 To resolve this error just try to remove @Stateless(mappedName = &#8220;Firstcalc&#8221;)  <a href="http://www.fouad-saidy.com/archives/12" class="more-link">More &#62;</a><p><a href="http://sharethis.com/item?&#038;wp=2.8.2&#38;publisher=c52c2557-5007-4da4-b176-d174646fb516&#38;title=Step+By+Step+Create+Simple+Calculator+using+Eclipse+Galileo+%26%23038%3B++EJB+3.0&#38;url=http%3A%2F%2Fwww.fouad-saidy.com%2Farchives%2F12">ShareThis</a></p>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: monospace; font-size: small;"><span class="Apple-style-span" style="font-size: 12px; line-height: 15px; white-space: pre-wrap;"><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; line-height: normal; white-space: normal;"></span></span></span><br />
<span style="font-family: monospace; font-size: small;"></span><br />
<span style="font-family: monospace; font-size: small;">
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<h2>Remark:</h2>
<p><span style="font-family: monospace;"><br />
I received many emails that talk about the error of <font color='red'> &#8220;Firstcalc not bound&#8221; </font> the problem that if you didn&#8217;t referenced the EJB project in the web application your server can not know the calcImpl class for this reason it shows this error.<br />
 To resolve this error just try to remove @Stateless(mappedName = &#8220;Firstcalc&#8221;) and replace it by @stateless,in the naming function in the servlet replace calc cl = (calc) ctx.lookup(&#8221;Firstcalc&#8221;); by  cl=(calc) ctx.lookup(&#8221;calcImpl/local&#8221;);<br />
I used the bounding without a mapped name of the calcImpl class, it&#8217;s Work correctly(tested with jboss server).<br />
</span></p>
<p>This tutorial is available in pdf book : <a href="http://www.scribd.com/doc/25396096/Step-By-Step-Create-Simple-Calculator-using-Eclipse-Galileo-EJB-3-0" style="display: inline !important; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal; margin-bottom: 6px; margin-left: auto; margin-right: auto; margin-top: 12px; text-decoration: underline;" title="View Step By Step Create Simple Calculator using Eclipse Galileo &amp;amp; EJB 3.0 on Scribd">Step By Step Create Simple Calculator using Eclipse Galileo &amp; EJB 3.0</a></div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
</div>
<p></span><br />
<span class="Apple-style-span" style="line-height: 15px; white-space: pre-wrap;"><span class="Apple-style-span" style="font-size: small;"><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">We will use in this tutorial:</span></span></span></p>
<ul>
<li><span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><a href="http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR1/eclipse-jee-galileo-SR1-win32.zip">Eclipse Galileo IDE</a> </span></span></li>
<li><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-family: Arial; font-size: 13px; white-space: pre;"><a href="http://sourceforge.net/projects/jboss/files/JBoss/JBoss-5.1.0.GA/">JBoss-5.1.0.GA</a></span></li>
</ul>
<div>
<span style="font-family: monospace; font-size: 12px; line-height: 15px; white-space: pre-wrap;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">we will create an application in the server side based on EJB 3.0, and an author web client application</span></span> </div>
<div>
<ol>
<li><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #3d85c6; font-family: Arial; font-size: 13px; font-weight: bold; white-space: pre;">Server Application Using EJB:</span></li>
</ol>
<div>
<ul>
<li><span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b><span style="color: #666666;">Configuration JBoss Server:</span></b></span></span></li>
</ul>
</div>
</div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">The second step is to configuarate the Jboss server in Eclipse Galieo IDE:</span></span> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">in Eclipse Menu choose Window&#8211;&gt; Preferences, then choose<br />
Server &#8211;&gt; Runtime Environments.</span></span> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">click add Button then choose JBoss&#8211;&gt; JBoss v5.0 and check&#8221; <b>Create a new local server</b>&#8221; </span></span></div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1LJB3YeWHI/AAAAAAAAAD0/P_3v7dnny74/s1600-h/jboss.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1LJB3YeWHI/AAAAAAAAAD0/P_3v7dnny74/s400/jboss.jpg" /></a> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">In Application Server Directory select the JBoss Server&nbsp;directory,<span style="color: red;"><br />
not the Content of the directory!</span> :</span></span> </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/_SIQbfFVpNY0/S1LJ5IuQ_WI/AAAAAAAAAD8/lwFHvEfqGLU/s1600-h/Jboss1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://1.bp.blogspot.com/_SIQbfFVpNY0/S1LJ5IuQ_WI/AAAAAAAAAD8/lwFHvEfqGLU/s400/Jboss1.jpg" /></a> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">you added the Jboss Server to Eclipse , now let&#8217;s add the Jboss Server<br />
to this section:</span></span> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">select the Server section clik and choose new-&gt;Server then next next<br />
until finish</span></span> </div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1LL4XY0DQI/AAAAAAAAAEM/sMQM9pz_aXg/s1600-h/jboss2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1LL4XY0DQI/AAAAAAAAAEM/sMQM9pz_aXg/s640/jboss2.jpg" /></a> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">the server appears like this in Server section:</span></span> </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/_SIQbfFVpNY0/S1LOkf8tQII/AAAAAAAAAEc/9ptHjspV6DA/s1600-h/jboss4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://3.bp.blogspot.com/_SIQbfFVpNY0/S1LOkf8tQII/AAAAAAAAAEc/9ptHjspV6DA/s400/jboss4.jpg" /></a> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">Now we will verify that Jdk is the default installed JRE&#8217;s :</span></span> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">select Window&#8211;&gt;Preferences in this windows select Java&#8211;&gt; Installed JREs<br />
then if jdk is not checked check it ,or add it if it doesn&#8217;t exist:</span></span> </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/_SIQbfFVpNY0/S1LNvu9mrSI/AAAAAAAAAEU/rJVrY1EEpz4/s1600-h/Jboss3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://1.bp.blogspot.com/_SIQbfFVpNY0/S1LNvu9mrSI/AAAAAAAAAEU/rJVrY1EEpz4/s400/Jboss3.jpg" /></a> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">we finished configuration step let&#8217;s move now to programming an<br />
EJB Application.</span></span> </div>
<div style="text-align: left;">
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div style="text-align: left;">
<ul>
<li><span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b><span style="color: #666666;">EJB Application</span></b>:</span></span></li>
</ul>
<div>
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">in this application we will create :</span></span> </div>
<div>
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">Remote Interface <b>calc</b>,</span></span> </div>
<div>
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">Class <b>calcImpl</b> which implements calc.</span></span> </div>
<div>
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">select File&#8211;&gt;New&#8211;&gt; Other.. then create EJB Project :</span></span> </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LRbwc41qI/AAAAAAAAAEk/qU8TT6j_cs0/s1600-h/jboss5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LRbwc41qI/AAAAAAAAAEk/qU8TT6j_cs0/s400/jboss5.jpg" /></a> </div>
<div class="separator" style="clear: both; text-align: left;">
specify the name of the project for example <b>SimpleCalculator</b>&nbsp;, and choose the JBoss v5 in target field: </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1LSUj1bEPI/AAAAAAAAAEs/vAY3rIT05Os/s1600-h/jboss6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1LSUj1bEPI/AAAAAAAAAEs/vAY3rIT05Os/s400/jboss6.jpg" /></a> </div>
<div>
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">now we created a simple ejb project ,we will create source code in ejbModule directory :</span></span> </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LTomPxL_I/AAAAAAAAAE0/2skblNP_y7M/s1600-h/Jboss7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LTomPxL_I/AAAAAAAAAE0/2skblNP_y7M/s400/Jboss7.jpg" /></a> </div>
<div>
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">we finished creating EJB project, create the interface calc with package first :</span></span> </div>
<div>
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LUfOtHwdI/AAAAAAAAAE8/C0mfwdUaBb0/s1600-h/jboss8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LUfOtHwdI/AAAAAAAAAE8/C0mfwdUaBb0/s320/jboss8.jpg" /></a> </div>
<div>
<span style="font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;">add this code to your calc interface:</span></span> </div>
<div>
<b><span style="color: #38761d;">package ejb;</span></b> </div>
<div>
<b><span style="color: #38761d;">import javax.ejb.Local;</span></b> </div>
<div>
<b><span style="color: #38761d;"></span></b></div>
<div>
<b><span style="color: #38761d;">@Local</span></b> </div>
<div>
<b><span style="color: #38761d;">public interface calc {</span></b> </div>
<div>
<span style="white-space: pre;"><b><span style="color: #38761d;"></span></b></span><b><span style="color: #38761d;">public float sum(float a,float b);</span></b> </div>
<div>
<span style="white-space: pre;"><b><span style="color: #38761d;"></span></b></span><b><span style="color: #38761d;">public float mult(float a,float b);</span></b> </div>
<div>
<span style="white-space: pre;"><b><span style="color: #38761d;"></span></b></span><b><span style="color: #38761d;">public float minus(float a,float b);</span></b> </div>
<div>
<b><span style="color: #38761d;">public float div(float a,float b);</span></b> </div>
<div>
<b><span style="color: #38761d;">}</span></b> </div>
<div>
next step is to create calcImpl with the same way dont forgit to specify the same package (ejb), and add this code to class: </div>
<div>
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>package ejb; import javax.ejb.Stateless;&nbsp;</b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>@Stateless(mappedName=&#8221;Firstcalc&#8221;)&nbsp;</b></span></span></p>
<p><span style="color: #6aa84f;"><span style="color: #38761d;"><b>public class calcImpl implements calc { </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>public float sum(float a,float b) </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>{ return a+b; } </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>public float mult(float a,float b) </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>{ return a*b; } </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>public float minus(float a,float b) </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>{ return a-b; } </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>public float div(float a,float b) { </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>try { </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>return a/b; </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>}catch(Exception e){ </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>System.out.println(&#8221;Error:devision by 0!!&#8221;); </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>return 0; &nbsp;</b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>} </b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>}&nbsp;</b></span></span><br />
<span style="color: #6aa84f;"><span style="color: #38761d;"><b>}</b></span> </span></div>
<div>
now we finished EJB Application let&#8217;s move to The Web Client Application. </p>
<ol>
<li value="2"><span style="color: #3d85c6;"><b>Web Client Application:</b></span></li>
</ol>
<div>
<b>select File&#8211;&gt;New&#8211;&gt;Dynamic Web Project , it&#8217;s name: SimpleCalculatorWeb</b> </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1LbTUH4VzI/AAAAAAAAAFE/GnAm3r24_9U/s1600-h/jboss9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1LbTUH4VzI/AAAAAAAAAFE/GnAm3r24_9U/s400/jboss9.jpg" /></a> </div>
<div>
add a jsp page called index to the <b>WebContent</b> directory : </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/_SIQbfFVpNY0/S1LhDcxvePI/AAAAAAAAAFc/oOE8z0OtaX8/s1600-h/jboss12.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://1.bp.blogspot.com/_SIQbfFVpNY0/S1LhDcxvePI/AAAAAAAAAFc/oOE8z0OtaX8/s320/jboss12.jpg" /></a> </div>
<div>
add this form to index.jsp:<br />
<span style="color: #38761d;"><b><br />
</b></span><br />
<span style="color: #38761d;"><b>&lt;h2&gt; &lt;b&gt; Hello World To The Simple Calculator &lt;/b&gt; &lt;/h2&gt;&nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;% float a=2,b=1; &nbsp;</b></span><br />
<span style="color: #38761d;"><b>if (request.getAttribute(&#8221;a&#8221;)!=null)&nbsp;</b></span><br />
<span style="color: #38761d;"><b>a=Float.parseFloat(request.getAttribute(&#8221;a&#8221;).toString()); &nbsp;</b></span><br />
<span style="color: #38761d;"><b>if( request.getAttribute(&#8221;b&#8221;)!=null) &nbsp;</b></span><br />
<span style="color: #38761d;"><b>b=Float.parseFloat(request.getAttribute(&#8221;b&#8221;).toString()); %&gt;</b></span><br />
<span style="color: #38761d;"><b>&lt;form method=&#8221;post&#8221; action=&#8221;calcServlet&#8221;&gt;&nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;b&gt;Number 1:&lt;/b&gt;&lt;input type=&#8217;text&#8217; name=&#8217;n1&#8242; value=&#8221;&lt;%=a%&gt;&#8221; /&gt; &lt;br/&gt;&nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;b&gt;Number 2:&lt;/b&gt;&lt;input type=&#8217;text&#8217; name=&#8217;n2&#8242; value=&#8221;&lt;%=b%&gt;&#8221; /&gt; &lt;br/&gt;&nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;u&gt;&lt;b&gt;Options:&lt;/b&gt;&lt;/u&gt; &lt;br/&gt;</b></span><br />
<span style="color: #38761d;"><b>&lt;ul&gt; &nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;li&gt;&lt;b&gt;+&lt;/b&gt;&lt;input type=&#8217;radio&#8217; name=&#8221;oper&#8221; value=&#8217;+&#8217; checked /&gt;&lt;/li&gt; &nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;li&gt;&lt;b&gt;&amp;nbsp;-&lt;/b&gt;&lt;input type=&#8217;radio&#8217; name=&#8221;oper&#8221; value=&#8217;-&#8217; /&gt;&lt;/li&gt;</b></span><br />
<span style="color: #38761d;"><b>&lt;li&gt;&lt;b&gt;*&lt;/b&gt;&lt;input type=&#8217;radio&#8217; name=&#8221;oper&#8221; value=&#8217;*&#8217; /&gt;&lt;/li&gt;&nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;li&gt;&amp;nbsp; &lt;b&gt;/&lt;/b&gt;&lt;input type=&#8217;radio&#8217; name=&#8221;oper&#8221; value=&#8217;/&#8217; /&gt;&lt;/li&gt; &lt;/ul&gt;&nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;b&gt;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&lt;/b&gt; &lt;br/&gt;&nbsp;</b></span><br />
<span style="color: #38761d;"><b>&lt;input type=&#8221;submit&#8221; value=&#8221;Executer&#8221; /&gt; &lt;/form&gt;</b></span><br />
<span style="color: #38761d;"><b>&lt;font color=&#8217;blue&#8217;&gt;&lt;b&gt;Result is: &lt;/b&gt; &lt;%=session.getAttribute(&#8221;result&#8221;)%&gt; &lt;/font&gt; &lt;br/&gt;</b></span><br />
<span style="color: #38761d;"><b>&lt;font color=&#8217;red&#8217; &gt;Error: &lt;%=session.getAttribute(&#8221;error&#8221;)%&gt;&lt;/font&gt;</b></span></p>
</div>
<div>
</div>
<div>
</div>
<div>
now create a <b>calServlet</b> with <b>web</b> package in the<strong> JavaResources :src</strong> directory : </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LcozaU1aI/AAAAAAAAAFM/UR3Ffldk_m4/s1600-h/jboss10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LcozaU1aI/AAAAAAAAAFM/UR3Ffldk_m4/s400/jboss10.jpg" /></a> </div>
<div>
servlet is created like this: </div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/_SIQbfFVpNY0/S1LdX21jqtI/AAAAAAAAAFU/HH3VUKJpp98/s1600-h/jboss11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://3.bp.blogspot.com/_SIQbfFVpNY0/S1LdX21jqtI/AAAAAAAAAFU/HH3VUKJpp98/s320/jboss11.jpg" /></a> </div>
<div>
add those import to your servlet class: </div>
<div>
<b><span style="color: #38761d;">import java.io.IOException;&nbsp;</span></b><br />
<b><span style="color: #38761d;">import javax.naming.*;&nbsp;</span></b><br />
<b><span style="color: #38761d;">import javax.servlet.*;</span></b><br />
<b><span style="color: #38761d;">import javax.servlet.*;&nbsp;</span></b><br />
<b><span style="color: #38761d;">import javax.servlet.http.*;</span></b><br />
<span style="color: #38761d;"><b><br />
</b></span></div>
<div>
</div>
<div>
copy this code to the doGet function : </div>
<div>
<span style="color: #38761d;"><b><br />
</b></span><br />
<b><span style="color: #38761d;">HttpSession session=request.getSession(true);&nbsp;</span></b><br />
<b><span style="color: #38761d;"></span></b><b><span style="color: #38761d;">RequestDispatcher rd=this.getServletContext().getRequestDispatcher(&#8221;/index.jsp&#8221;); &nbsp;</span></b></p>
<p><b><span style="color: #38761d;"></span></b><b><span style="color: #38761d;">float a=Float.parseFloat(request.getParameter(&#8221;n1&#8243;)); &nbsp;</span></b> <b><span style="color: #38761d;">&nbsp;</span></b><br />
<b><span style="color: #38761d;">float b=Float.parseFloat(request.getParameter(&#8221;n2&#8243;)); &nbsp;</span></b> <b><span style="color: #38761d;">&nbsp;</span></b><br />
<b><span style="color: #38761d;">char oper=request.getParameter(&#8221;oper&#8221;).charAt(0); </span></b><b><span style="color: #38761d;">&nbsp;</span></b><br />
<b><span style="color: #38761d;">float result=0; </span></b><br />
<b><span style="color: #38761d;"></span></b><b><span style="color: #38761d;">try { </span></b><b><span style="color: #38761d;"></span></b><br />
<b><span style="color: #38761d;">Context ctx=new InitialContext(); </span></b><b><span style="color: #38761d;"></span></b><br />
<span style="color: #38761d;"><b>// call the calcImpl class of the SimpleCalculator EJB with the mappedName </b></span><br />
<b><span style="color: #38761d;">calc cl=(calc) ctx.lookup(&#8221;Firstcalc&#8221;); </span></b><b><span style="color: #38761d;">&nbsp;</span></b><br />
<b><span style="color: #38761d;">switch(oper) </span></b><b><span style="color: #38761d;">&nbsp;</span></b><br />
<b><span style="color: #38761d;">{ </span></b><br />
<b><span style="color: #38761d;">case &#8216;+&#8217;: result=cl.sum(a, b); </span></b><b><span style="color: #38761d;">break; </span></b><b><span style="color: #38761d;">&nbsp;</span></b><br />
<b><span style="color: #38761d;">case &#8216;-&#8217;: result =cl.minus(a, b); </span></b><b><span style="color: #38761d;">break; </span></b><br />
<b><span style="color: #38761d;"></span></b><b><span style="color: #38761d;">case &#8216;*&#8217;: result =cl.mult(a, b); </span></b><b><span style="color: #38761d;">break;</span></b> </div>
<div>
<span style="color: #38761d; font-weight: bold;">case &#8216;/&#8217;: result =cl.div(a, b);</span> <b><span style="color: #38761d;">break; </span></b><br />
<b><span style="color: #38761d;">} </span></b><br />
<b><span style="color: #38761d;">session.setAttribute(&#8221;result&#8221;,result); request.setAttribute(&#8221;a&#8221;, a); request.setAttribute(&#8221;b&#8221;, b); </span></b><br />
<b><span style="color: #38761d;">}catch(NamingException e){ </span></b><br />
<b><span style="color: #38761d;">session.setAttribute(&#8221;erreur: &#8220;,e.getMessage()); </span></b><br />
<b><span style="color: #38761d;">} </span></b><br />
<b><span style="color: #38761d;">rd.forward(request,response);</span></b> </div>
<ol></ol>
</div>
<div>
</div>
<div>
</div>
</div>
<p>to let the the web client application to know the calc interface we must configure the build path of the project in adding the first project&nbsp;<span style="font-weight: bold;">SimpleCalculator :</span></p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/_SIQbfFVpNY0/S1Lmra0NDiI/AAAAAAAAAFk/yWVmq3JC38U/s1600-h/jboss13.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://3.bp.blogspot.com/_SIQbfFVpNY0/S1Lmra0NDiI/AAAAAAAAAFk/yWVmq3JC38U/s640/jboss13.jpg" /></a></div>
<p>in the project section click add &nbsp;and select<b> SimpleCalculator:&nbsp;</b></p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/_SIQbfFVpNY0/S1Ln4qrIU1I/AAAAAAAAAFs/fXXgxlCe-c0/s1600-h/jboss14.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://3.bp.blogspot.com/_SIQbfFVpNY0/S1Ln4qrIU1I/AAAAAAAAAFs/fXXgxlCe-c0/s400/jboss14.jpg" /></a></div>
<p>now add this import to your servlet class :<br />
<b><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #38761d; font-family: Arial; font-size: 13px; white-space: pre;">import ejb.calc;</span></b><br />
<span style="color: #38761d; font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b><br />
</b></span></span><br />
<span style="color: #38761d; font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b>let&#8217;s deploy the two project ,firstly play the JBoss Server in Server section:</b></span></span></p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1Lr0ozzJlI/AAAAAAAAAF0/ZHGHAEPCaL8/s1600-h/jboss15.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://2.bp.blogspot.com/_SIQbfFVpNY0/S1Lr0ozzJlI/AAAAAAAAAF0/ZHGHAEPCaL8/s320/jboss15.jpg" /></a></div>
<p><span style="color: #38761d; font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b>deploying the EJB Project :</b></span></span></p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LsZinxh2I/AAAAAAAAAF8/AGGUDZo4ha8/s1600-h/jboss16.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1LsZinxh2I/AAAAAAAAAF8/AGGUDZo4ha8/s400/jboss16.jpg" /></a></div>
<p><span style="color: #38761d; font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b><br />
</b></span></span><br />
<span style="color: #38761d; font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b>with the same way deploy SimpleCalculatorWeb:</b></span></span></p>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1MMUjVo5_I/AAAAAAAAAGE/tXh0s1AqBUI/s1600-h/Jboss17.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" rel="lightbox-12"><img border="0" src="http://4.bp.blogspot.com/_SIQbfFVpNY0/S1MMUjVo5_I/AAAAAAAAAGE/tXh0s1AqBUI/s640/Jboss17.jpg" /></a></div>
<p><span style="color: #38761d; font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b>if you have any remarks or questions dont hesitate to post it.<br />
</b></span></span><br />
<span style="color: #38761d; font-family: Arial; font-size: small;"><span style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 13px; white-space: pre;"><b><br />
</b></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fouad-saidy.com/archives/12/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

