Wednesday, February 10, 2010

Sunday, January 17, 2010

Step By Step Create Simple Calculator using Eclipse Galileo & EJB 3.0


this is the tutorial available in pdf book : Step By Step Create Simple Calculator using Eclipse Galileo & EJB 3.0


We will use in this tutorial:
we will create an application in the server side based on EJB 3.0, and an author web client application
  1. Server Application Using EJB:
  • Configuration JBoss Server:

The second step is to configuarate the Jboss server in Eclipse Galieo IDE:
in Eclipse Menu choose Window--> Preferences, then choose
Server --> Runtime Environments.


click add Button then choose JBoss--> JBoss v5.0 and check" Create a new local server"



In Application Server Directory select the JBoss Server directory,
not the Content of the directory!
:



you added the Jboss Server to Eclipse , now let's add the Jboss Server
to this section:

select the Server section clik and choose new->Server then next next
until finish




the server appears like this in Server section:



Now we will verify that Jdk is the default installed JRE's :
select Window-->Preferences in this windows select Java--> Installed JREs
then if jdk is not checked check it ,or add it if it doesn't exist:


we finished configuration step let's move now to programming an
EJB Application.


  • EJB Application:
in this application we will create :
Remote Interface calc,
Class calcImpl which implements calc.
select File-->New--> Other.. then create EJB Project :

specify the name of the project for example SimpleCalculator , and choose the JBoss v5 in target field:

now we created a simple ejb project ,we will create source code in ejbModule directory :

we finished creating EJB project, create the interface calc with package first :


add this code to your calc interface:

package ejb;
import javax.ejb.Local;

@Local
public interface calc {
public float sum(float a,float b);
public float mult(float a,float b);
public float minus(float a,float b);
public float div(float a,float b);
}
next step is to create calcImpl with the same way dont forgit to specify the same package (ejb), and add this code to class:
package ejb; import javax.ejb.Stateless; 
@Stateless(mappedName="Firstcalc") 

public class calcImpl implements calc {
public float sum(float a,float b)
{ return a+b; }
public float mult(float a,float b)
{ return a*b; }
public float minus(float a,float b)
{ return a-b; }
public float div(float a,float b) {
try {
return a/b;
}catch(Exception e){
System.out.println("Error:devision by 0!!");
return 0;  
}

}
now we finished EJB Application let's move to The Web Client Application.
  1. Web Client Application:
select File-->New-->Dynamic Web Project , it's name: SimpleCalculatorWeb

add a jsp page called index to the WebContent directory :

add this form to index.jsp:


<h2> <b> Hello World To The Simple Calculator </b> </h2> 
<% float a=2,b=1;  
if (request.getAttribute("a")!=null) 
a=Float.parseFloat(request.getAttribute("a").toString());  
if( request.getAttribute("b")!=null)  
b=Float.parseFloat(request.getAttribute("b").toString()); %>
<form method="post" action="calcServlet"> 
<b>Number 1:</b><input type='text' name='n1' value="<%=a%>" /> <br/> 
<b>Number 2:</b><input type='text' name='n2' value="<%=b%>" /> <br/> 
<u><b>Options:</b></u> <br/>
<ul>  
<li><b>+</b><input type='radio' name="oper" value='+' checked /></li>  
<li><b>&nbsp;-</b><input type='radio' name="oper" value='-' /></li>
<li><b>*</b><input type='radio' name="oper" value='*' /></li> 
<li>&nbsp; <b>/</b><input type='radio' name="oper" value='/' /></li> </ul> 
<b>-------------------------------------------</b> <br/> 
<input type="submit" value="Executer" /> </form>
<font color='blue'><b>Result is: </b> <%=session.getAttribute("result")%> </font> <br/>
<font color='red' >Error: <%=session.getAttribute("error")%></font>

now create a calServlet with web package in the JavaResources :src directory :

servlet is created like this:

add those import to your servlet class:
import java.io.IOException; 
import javax.naming.*; 
import javax.servlet.*;
import javax.servlet.*; 
import javax.servlet.http.*;


copy this code to the doGet function :


HttpSession session=request.getSession(true); 
RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/index.jsp");  

float a=Float.parseFloat(request.getParameter("n1"));    
float b=Float.parseFloat(request.getParameter("n2"));    
char oper=request.getParameter("oper").charAt(0);  
float result=0;
try {
Context ctx=new InitialContext();
// call the calcImpl class of the SimpleCalculator EJB with the mappedName
calc cl=(calc) ctx.lookup("Firstcalc");  
switch(oper)  
{
case '+': result=cl.sum(a, b); break;  
case '-': result =cl.minus(a, b); break;
case '*': result =cl.mult(a, b); break;
case '/': result =cl.div(a, b); break;
}
session.setAttribute("result",result); request.setAttribute("a", a); request.setAttribute("b", b);
}catch(NamingException e){
session.setAttribute("erreur: ",e.getMessage());
}
rd.forward(request,response);


    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 SimpleCalculator :

    in the project section click add  and select SimpleCalculator: 


    now add this import to your servlet class :
    import ejb.calc;


    let's deploy the two project ,firstly play the JBoss Server in Server section:

    deploying the EJB Project :



    with the same way deploy SimpleCalculatorWeb:


    if you have any remarks or questions dont hesitate to post it.


    Wednesday, January 28, 2009

    Electronic War Against zionist



    The First Thing That I wounder when I saw Our Brothers and sisters killed in Gaza is how We can Help them more then expressing disappointment and sadness ? How we can be in action against israel war crimes in Gaza?

    the practise way that I saw is what a lot of Norwegian young peoples do , they try all the time to hack zionist websites, to explain to the world the Right of Palestinians To live in freedom, to have their country without any colonization of zionist,they called israel the Nazi country in 21 th century.

    This way is the efficient methods to help Palestine because demonstration or expressing Solidarity, yes it is necessary but, it is not enough .

    In This Time Hacking zionist websites it is not just a good things to do but it becomes an obligation to do for any Muslim can use a computer , this is some statistic of hacking zionist websites.

    The attack in the virtual world in order to protest Israel aggression in Gaza, Palestine, is still ongoing. There are more than 10,000 sites that Israel is deface.

    Zone-H.org A site that records the action web defacement have said that 10,413 attacks against sites with domain names. il (israel). 10,413 from the attack, have mentioned 3485 in the form of a single IP and 6928 mass attack.

    Messages from the thousands of generally the same. Here are some message that the hackers had read :

    • “Stop The War, Stop killing People & Child. Free Gaza Now” (Ashiyane Digital Security Team)
    • “Stop attacks u israel and usa ! you cursed nations ! one day Muslims will clean the world from you !” (Agd_Scorpio)
    • “This Hack iS To Defend Islam That Has Been Harassed by Denmark and usa and israel (FesH4ck3rs Team)
    • “Stop WAR israel to Palestine!!!” (Old.Zone)
    • “You have weapons, you have technology But We have our ALLAH & Our Faith” (xOOmxOOm)

    this is a simple program to use it is a good way to bombard zionist websites it is easy to use just write an address of zionist websites and select the number of attacks that you want to do and click start,you can see the program begin to send a lot of request to the zionist server in order to stop it.
    Tsonamy

    watch an example of kadima website hacked.

    Monday, January 26, 2009

    Microsoft is laying off 5,000 workers




    "Microsoft is laying off 5,000 workers" when I saw this news headline ( or I can say a bad news) in Aljazeera channel I was upset and sad for this decision of the biggest Company of Softeware in the whole world ,The job losses will affect workers in a variety of departments, including research and development, sales, marketing, finance, and human resources. But Microsoft plans to keep hiring workers in areas where business is still growing, such as Internet search service.
    In my opininion this decision will create a lot of problems for computing domain in general ,and it is coming from the results of the World Financial Crisis.
    I hope that things go good to keep the 5000 workers jobs and also to save Computing in the world .



    Xquery Interview



    During My surfing in the net I found an article which is an interview with The co-inventor of XQuery Jonathan Robie, in which he talks about the XQuery implementations( DataDirect) ,the Java API for using Xquery languages in java called XQJ it is an important interview which shows the use of Xquery and its futur.
    this is the link of this interview:

    http://www.stylusstudio.com/interviews/jonathan_robie.html

    JavaFx the new Generation of RIA



    JavaFX is a family of software products for creating rich Internet applications, web applications that have the features and functionality of traditional desktop applications, including interactive multimedia applications. The JavaFX products can build applications for desktop, mobile, TV and other platforms. Currently (January 2009)[update] only the Microsoft Windows and Mac OS operating systems officially support JavaFX.JavaFX has two components:JavaFX Script, a declarative language intended to make Swing easier to use for interface programmers or visual designers familiar with scripting languages. In JavaFX Script, the structure of the programming code is supposed to closely match the layout of the GUI. JavaFX Mobile, a Java operating system for mobile devices, including PDAs, smartphones and feature phones. It features a Java SE and Java ME implementation running on top of a Linux kernel
    Source: www.wikipedia.com


    for more information on how to use this softeware ,for download also http://javafx.com/
     

    @ Copyright 2009 for The Contributors Of This Blog @