<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0' gd:etag='W/&quot;AkAHQH0yfCp7ImA9WhVUGEU.&quot;'><id>tag:blogger.com,1999:blog-8900093511482677774</id><updated>2012-05-24T12:45:31.394-07:00</updated><title>JEE Best Practices</title><subtitle type='html'>Java/JEE exemple avec des best practices</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jee-best-practices.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default?redirect=false&amp;v=2'/><link rel='alternate' type='text/html' href='http://jee-best-practices.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Karim Ayari</name><uri>https://profiles.google.com/102337987242147563828</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry gd:etag='W/&quot;DEYFQng4cCp7ImA9WhVUGE0.&quot;'><id>tag:blogger.com,1999:blog-8900093511482677774.post-6007600057666781316</id><published>2012-05-23T13:48:00.000-07:00</published><updated>2012-05-23T13:48:33.638-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2012-05-23T13:48:33.638-07:00</app:edited><title>How to create thumbnails using Java</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;h3 class="r" style="text-align: left;"&gt;

&lt;span style="font-size: small;"&gt;&lt;a alt="How to create thumbnails of image in java" class="l" href="http://www.blogger.com/blogger.g?blogID=8900093511482677774"&gt;Creating thumbnails with Java :&lt;/a&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;h4 class="r" style="text-align: left;"&gt;
&lt;span style="color: black; font-size: 100%;"&gt;&lt;span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"&gt;&lt;span style="font-weight: normal;"&gt;This programm loads an image from the source and create the Thumbnails with saving it to source location, an additonal parameter will be added like the width and hight of the thumb&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h4&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8900093511482677774-6007600057666781316?l=jee-best-practices.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jee-best-practices.blogspot.com/feeds/6007600057666781316/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://jee-best-practices.blogspot.com/2012/05/how-to-create-thumbnails-using-java.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/6007600057666781316?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/6007600057666781316?v=2'/><link rel='alternate' type='text/html' href='http://jee-best-practices.blogspot.com/2012/05/how-to-create-thumbnails-using-java.html' title='How to create thumbnails using Java'/><author><name>Karim Ayari</name><uri>https://profiles.google.com/102337987242147563828</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;AkAHQHo7eSp7ImA9WhVUGEU.&quot;'><id>tag:blogger.com,1999:blog-8900093511482677774.post-1611228593425355737</id><published>2011-02-22T01:51:00.001-08:00</published><updated>2012-05-24T12:45:31.401-07:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2012-05-24T12:45:31.401-07:00</app:edited><title>Simple exemple : JSF 2.0, PRIMEFACES 2.2.RC, EJB 3.1, JPA 2</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this tutorial we are going to start developing our rich web
application using &lt;span style="font-weight: bold;"&gt;JSF 2&lt;/span&gt; , &lt;span style="font-weight: bold;"&gt;PRIMFACES&lt;/span&gt; , &lt;span style="font-weight: bold;"&gt;EJB&lt;/span&gt; and &lt;span style="font-weight: bold;"&gt;JPA&lt;/span&gt;&lt;br /&gt;
we can create the project&amp;nbsp; using your preferred IDE ,the most
convenient method of creating a new project is to use an IDE that
supports it (for example, &lt;a href="http://www.eclipse.org/downloads/" title="Eclipse IDE"&gt;Eclipse&lt;/a&gt; with plugin, &lt;a href="http://netbeans.org/" title="NetBeans IDE"&gt;NetBeans&lt;/a&gt;, &lt;a href="http://www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html" title="Jdeveloper IDE"&gt;JDeveloper&lt;/a&gt;) &lt;br /&gt;
I will explain all of the steps to build an empty &lt;strong&gt;web
application&lt;/strong&gt; project using &lt;a href="http://netbeans.org/" title="netBeans"&gt;&lt;span style="font-weight: bold;"&gt;netbeans&lt;/span&gt;&lt;/a&gt;
and &lt;a href="https://glassfish.dev.java.net/" title="glassFish"&gt;&lt;span style="font-weight: bold;" title="glassFish"&gt;glassFish 3&lt;/span&gt;&lt;/a&gt; .&lt;br /&gt;
A simple  insert into phone_book &lt;strong&gt;data base&lt;/strong&gt; and show the list of ccontact saved here the&lt;strong&gt; script of creation&lt;/strong&gt;&lt;br /&gt;
&lt;pre class="brush: js"&gt;CREATE DATABASE phone_book

CREATE TABLE contact (
    id integer NOT NULL,
    name character varying(20),
    surname character varying(20),
    mobile_phone character varying(15),
    email character varying(100)
);

ALTER TABLE ONLY contact
    ADD CONSTRAINT contact_pkey PRIMARY KEY (id);
&lt;/pre&gt;
&lt;big style="font-weight: bold;"&gt;Download
and install&lt;/big&gt;

&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://netbeans.org/" title="NetBeans IDE"&gt;Last NetBeans
version 6.9 &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.primefaces.org/downloads.html" title="primfaces exemple"&gt;PrimFaces 2.2 JAR&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://javaserverfaces.dev.java.net/download.html" title="mojarra"&gt;Mojarra 2.0.3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
Note - it is required to use java&amp;nbsp;&lt;a href="http://www.oracle.com/technetwork/java/javase/overview/index-jsp-136246.html" title="java JEE jdk6"&gt;&lt;strong&gt;JDK 6&lt;/strong&gt;&lt;/a&gt;&amp;nbsp; : to check for
  java installation in windows or linux use " java -version "&amp;nbsp; in
  command line
&lt;br /&gt;
&lt;h4&gt;
 Creating the project &lt;/h4&gt;
Here we will create the web application EAR , Open netBeans and go to &lt;br /&gt;File &amp;gt; New Project &amp;gt; Java EE &amp;gt; Entreprise Aplication &amp;gt; Next&lt;br /&gt; 
Put the name (PhoneBook for exemple) and location for your project go to next&lt;br /&gt;
NetBeans use GlassFish 3 default server the screen chould be like :
&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
  &lt;tbody&gt;
&lt;tr&gt;
    &lt;td&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-u6lXW7qLDWk/TWQYDA1g2bI/AAAAAAAAABA/O4K7m8jAu4E/s1600/Capture.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="145" src="http://3.bp.blogspot.com/-u6lXW7qLDWk/TWQYDA1g2bI/AAAAAAAAABA/O4K7m8jAu4E/s320/Capture.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;
  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;table&gt;
  &lt;tbody&gt;
&lt;tr&gt;
    &lt;td&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-LOuIZNvlYEs/TWQYMSCPXdI/AAAAAAAAABE/qM2y2TIfpXU/s1600/capture2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-LOuIZNvlYEs/TWQYMSCPXdI/AAAAAAAAABE/qM2y2TIfpXU/s320/capture2.PNG" width="219" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/td&gt;
    &lt;td&gt;Netbeans create the structure of web application project&lt;br /&gt;
Now we will add JSF 2  : &lt;br /&gt;
Got to BookPhone-War &amp;gt; right click with mouse &amp;gt; in Categories go to Framwork &amp;gt; Java Server Face&lt;br /&gt;
( if you dont have jsf  option framwork  you need to update netBeans plugin go to tools &amp;gt; plugins ) and confirm add librairie
    &lt;/td&gt; 
  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
the web.xml is update and should look  : 
&lt;br /&gt;
&lt;pre class="brush: js"&gt;&lt;web-app version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;
    &lt;context-param&gt;
        &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
        &lt;param-value&gt;Development&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
        &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;session-config&gt;
        &lt;session-timeout&gt;30&lt;/session-timeout&gt;
    &lt;/session-config&gt;
    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;faces/index.xhtml&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
&lt;/web-app&gt;

&lt;/pre&gt;
&lt;h4&gt;
 Now we will create jpa entity from data base &lt;/h4&gt;
&lt;br /&gt;
In PhoneBook-ejb go to source package &amp;gt; right click &amp;gt; New &amp;gt; Persistance &amp;gt; Entity classes from data base &amp;gt; next &lt;br /&gt;
We will create connection using jpa to database &lt;br /&gt;
Data source &amp;gt; choise New DataSource &amp;gt; put name like phone_book into jndi name input &amp;gt; next ower New Data Base connection should look &lt;br /&gt;

&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/--HjKKGxwxwE/TWQYY8Mih9I/AAAAAAAAABI/KtJUjP56qsc/s1600/connection.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="176" src="http://1.bp.blogspot.com/--HjKKGxwxwE/TWQYY8Mih9I/AAAAAAAAABI/KtJUjP56qsc/s320/connection.PNG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Than choise the data base schema must be public select contact table from availabe table &amp;gt; enter the entity package like com.project.phone.entity the Contact entity Class is 
&lt;br /&gt;
&lt;pre class="brush: js"&gt;package org.project.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "contact")
public class Contact implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "name")
    private String name;
    @Column(name = "surname")
    private String surname;
    @Column(name = "mobile_phone")
    private String mobilePhone;
    @Column(name = "email")
    private String email;

    public Contact() {
    }

    public Contact(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Contact)) {
            return false;
        }
        Contact other = (Contact) object;
        if ((this.id == null &amp;amp;&amp;amp; other.id != null) || (this.id != null &amp;amp;&amp;amp; !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.project.entity.Contact[id=" + id + "]";
    }

}

&lt;/pre&gt;
&lt;h4&gt;
 Now we will create the first welcome page contains a form to add person &lt;/h4&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8900093511482677774-1611228593425355737?l=jee-best-practices.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jee-best-practices.blogspot.com/feeds/1611228593425355737/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/simple-exemple-jsf-20-primefaces-22rc.html#comment-form' title='2 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/1611228593425355737?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/1611228593425355737?v=2'/><link rel='alternate' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/simple-exemple-jsf-20-primefaces-22rc.html' title='Simple exemple : JSF 2.0, PRIMEFACES 2.2.RC, EJB 3.1, JPA 2'/><author><name>Jean</name><uri>http://www.blogger.com/profile/15925637809573494664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-u6lXW7qLDWk/TWQYDA1g2bI/AAAAAAAAABA/O4K7m8jAu4E/s72-c/Capture.PNG' height='72' width='72'/><thr:total>2</thr:total></entry><entry gd:etag='W/&quot;C0MHRnY_cSp7ImA9Wx9bE08.&quot;'><id>tag:blogger.com,1999:blog-8900093511482677774.post-1751716975559233829</id><published>2011-02-21T11:33:00.001-08:00</published><updated>2011-02-21T12:50:37.849-08:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-02-21T12:50:37.849-08:00</app:edited><title>Upload files with JSF and primfaces</title><content type='html'>&lt;div dir="ltr" style="text-align: left;font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;" trbidi="on"&gt;
  &lt;p&gt;the current versions of the Java web standards (servlets, JSP, and JSF) do not offer any help for upload files or pictures. Fortunately, there are third-party frameworks, such as  &lt;a href="http://jakarta.apache.org/commons/fileupload/" title="commons file upload"&gt;Apache Commons File Upload&lt;/a&gt;, &lt;a href="http://myfaces.apache.org/" title="myFaces"&gt;Apache Tomahowk&lt;/a&gt;, &lt;a href="http://www.jboss.org/richfaces" title="Richfaces"&gt; Richfaces&lt;/a&gt;, and primfaces &lt;/p&gt;
  &lt;p&gt;Primfaces provide JSF components that go beyond the JSF specification. These components are  compatible with the  JSF 2 with a little of bug &lt;/p&gt;
  &lt;p&gt;This article aims to provide detailed steps to develop an exemple of&lt;strong&gt; how to upload file using jsf 2 and primfaces and how to show it again into xhtml file.&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt;The example in this tutorial creates a web page named :&lt;br /&gt; 
  &lt;ul&gt;
  &lt;li&gt;upload_file.xhtml : contains a form for upload picture&lt;/li&gt;
  &lt;li&gt;show_image.xhtml to show picture&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;&lt;h4&gt;Preaparing the exemple&lt;/h4&gt;
  We need those librairies into project class path:
   &lt;ul&gt;
   &lt;li&gt; &lt;strong&gt;&lt;a href="" title="Primfaces jar" &gt;Primfaces component libraire&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
   &lt;li&gt; &lt;a href="http://commons.apache.org/io/download_io.cgi" title="Commons io" &gt;&lt;strong&gt;Commons-io&lt;/strong&gt;&lt;/a&gt;  &lt;/li&gt;
   &lt;li&gt; &lt;a href="http://commons.apache.org/fileupload/download_fileupload.cgi" title="fileupload" &gt;&lt;strong&gt;Commons-FileUpload&lt;/strong&gt;&lt;/a&gt;  &lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt; After adding the &lt;strong&gt;JAR&lt;/strong&gt;'s to class path we need to make changes into web.xml :&lt;/p&gt;
  &lt;pre class="brush: js"&gt;
      &lt;filter&gt;
        &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
        &lt;filter-class&gt;org.primefaces.webapp.filter.FileUploadFilter
        &lt;/filter-class&gt;
        
        &lt;init-param&gt;
            &lt;param-name&gt;thresholdSize&lt;/param-name&gt;
            &lt;param-value&gt;51200&lt;/param-value&gt;
        &lt;/init-param&gt;
   
        &lt;init-param&gt;
            &lt;param-name&gt;uploadDirectory&lt;/param-name&gt;
            &lt;param-value&gt;/tmpDir/&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/filter&gt;

    &lt;filter-mapping&gt;
        &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt;
        &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;/filter-mapping&gt;
&lt;/pre&gt;
&lt;p&gt;
Before creating the JSF pages and managed bean , we need first to add ower class Utils in my last post &lt;a href="http://jee-best-practices.blogspot.com/2011/02/image-to-byte-array-and-byte-array-to.html" title="Image to byte array and byte array to image"&gt;Image to byte array and byte array to image&lt;/a&gt;&lt;br /&gt;
this methode will be used : &lt;br /&gt;
&lt;pre class="brush: js"&gt;
public static byte[] InputStreamToByte(InputStream fis) throws FileNotFoundException {

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        try {
            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);

                System.out.println("read " + readNum + " bytes,");
            }
            byte[] bytes = bos.toByteArray();

            return bytes;
        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }


    }
&lt;/pre&gt;
and to create the &lt;strong&gt;jsf 2 managed bean&lt;/strong&gt; which will be providing the required services for the JSF pages that will be created later dont forget getters and setters methode : &lt;br /&gt;
&lt;pre class="brush: js"&gt;
@ManagedBean
@SessionScoped
public class UploadImage {

 private StreamedContent image;

    /**
     * Used to upload image from jsf pages
     * @param event
     */
    public String imageUpload(FileUploadEvent event) {

        try {
            /** Convert file from input stream to bytes */
            byte[] bytearray = Utils.InputStreamToByte(event.getFile().getInputstream()) 
            /*
             * bytearray used to store picture into database 
             */  
            InputStream ist = new ByteArrayInputStream(bytearray);
            /*
             * StreamedContent Object used to show the picture in jsf pages
             * we need to convert again bytearray to InputStream
             */
            image = new DefaultStreamedContent(ist, "image/jpg");

            FacesMessage msg = new FacesMessage("Succesful picture is uploaded.");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            /** we dont need to use faces-config to navigate in jsf 2 */
            return "/show_image.xhtml"

        } catch (Exception e) {
            FacesMessage msg = new FacesMessage("Exception happen");
            FacesContext.getCurrentInstance().addMessage(null, msg);
            e.printStackTrace();
            return null;

        }

    }

}
&lt;/pre&gt;
 Now, we are ready to create the first &lt;strong&gt;web page&lt;/strong&gt; named upload_file.xhtml that contains a form to upload file
&lt;pre class="brush: js"&gt; 
 &lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
                
                &lt;h:form&gt;
                &lt;h:panelGrid columns="2" width="100%" &gt;
                    &lt;h:outputText value="Image to upload" /&gt;
                    &lt;p:fileUpload fileUploadListener="#{uploadImage.imageUpload}" auto="true" allowTypes="*.jpg;*.png;*.gif;*.jpeg;" description="Image" /&gt;
                    
                &lt;/h:form&gt;
 &lt;/pre&gt;
 
Create the next web page named show_file.xhtml that contains a tag to show image 
 &lt;pre class="brush: js"&gt; 
 &lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
                
                &lt;h:form&gt;
                
                 &lt;p:graphicImage  value="#{uploadImage.image}" id="imgage" width="140" /&gt;
                    
                &lt;/h:form&gt;
 &lt;/pre&gt;
 Note -&lt;strong&gt; you can add ajax fonction&lt;/strong&gt; to show picture when upload just in your managed bean change imageUpload methode to retur void and copy &lt;strong&gt;p:graphicImage&lt;/strong&gt; into upload_image.picture and add update="image" to &lt;strong&gt;p:fileUpload&lt;/strong&gt; tag
&lt;/p&gt;

&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8900093511482677774-1751716975559233829?l=jee-best-practices.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jee-best-practices.blogspot.com/feeds/1751716975559233829/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/upload-files-with-jsf-and-primfaces.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/1751716975559233829?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/1751716975559233829?v=2'/><link rel='alternate' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/upload-files-with-jsf-and-primfaces.html' title='Upload files with JSF and primfaces'/><author><name>Jean</name><uri>http://www.blogger.com/profile/15925637809573494664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;A0YERn4_eyp7ImA9Wx9bEk0.&quot;'><id>tag:blogger.com,1999:blog-8900093511482677774.post-1101807506185509391</id><published>2011-02-20T05:38:00.000-08:00</published><updated>2011-02-20T05:38:27.043-08:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-02-20T05:38:27.043-08:00</app:edited><title>Etude comparatif entre les framworks de présentation JEE</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div  style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;" &gt;
  &lt;p&gt; Voir le nombre important de &lt;a href="#" title="framwork" style="text-decoration: none" &gt; Framework &lt;/a&gt; destinés aux développements de la couche présentation en &lt;a href="#" title="java" style="text-decoration: none" &gt; &lt;strong&gt;java&lt;/strong&gt;&lt;/a&gt; &lt;a href="#" title="java j2ee" style="text-decoration: none" &gt; &lt;strong&gt;j2ee&lt;/strong&gt;&lt;/a&gt;, le choix d’une solution se base sur les principales fonctionnalités et besoins et ressources (qualité, interopérabilité, évolutive ainsi que le temps de production de maquettes de la charte graphique et la présentation des interfaces attractives). Les plus connus dans la communauté freeware sont &lt;strong&gt;&lt;a href="#" title="JSF richfaces" style="text-decoration: none" &gt;JSF-Richfaces &lt;/a&gt;,&lt;a href="#" title="spring" style="text-decoration: none" &gt; Spring MVC &lt;/a&gt;, &lt;a href="#" title="struts" style="text-decoration: none" &gt; Struts &lt;/a&gt;, &lt;/strong&gt;&lt;strong&gt; &lt;a href="#" title="gwt" style="text-decoration: none" &gt;GWT&lt;/a&gt;,&lt;a href="#" title="wicket" style="text-decoration: none" &gt; WICKET &lt;/a&gt;, &lt;a href="#" title="flex" style="text-decoration: none" &gt; FLEX &lt;/a&gt; &lt;/strong&gt;. &lt;/p&gt;
  &lt;p&gt; &lt;u&gt;&lt;strong&gt;WICKET&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;
  &lt;p&gt; Wicket est un framework à base de composants, à l'inverse des frameworks &lt;a href="http://fr.wikipedia.org/wiki/Mod%C3%A8le-Vue-Contr%C3%B4leur" title="Modèle-Vue-Contrôleur"&gt;&lt;strong&gt;MVC&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; &lt;/strong&gt; Modèle-Vue-Contrôleur traditionnels à base d'actions, comme Apache &lt;a href="http://fr.wikipedia.org/wiki/Apache_Struts" title="Apache Struts"&gt;&lt;strong&gt;Struts&lt;/strong&gt;&lt;/a&gt; ou &lt;a href="http://fr.wikipedia.org/wiki/Spring_Framework" title="Spring Framework"&gt;&lt;strong&gt;Spring MVC&lt;/strong&gt;&lt;/a&gt; par exemple &lt;/p&gt;
  &lt;p&gt;&lt;strong&gt;Avantages :&lt;/strong&gt; &lt;br /&gt;
    &lt;br /&gt;
  &lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Utilise exclusivement les pages &lt;a href="http://fr.wikipedia.org/wiki/XHTML" title="XHTML" &gt;XHTML&lt;/a&gt; comme technologie de présentation. De plus, il n'y a aucune logique à écrire directement dans les pages &lt;a href="http://fr.wikipedia.org/wiki/XHTML" title="XHTML"&gt;XHTML&lt;/a&gt;.&lt;/li&gt;
    &lt;li&gt;Wicket permet de séparer l’HTML et le code Java.&lt;/li&gt;
    &lt;li&gt;Véritable séparation entre la partie cliente et la partie serveur.&lt;/li&gt;
    &lt;li&gt;Pas de fichier de configuration : une classe définie dans le web.xml sert de point d’entrée Pas de configuration complexe (&lt;strong&gt;XML&lt;/strong&gt;).&lt;/li&gt;
    &lt;li&gt;Navigation entre les pages définies en &lt;a href="#" title="java jee" style="text-decoration: none" &gt; Java&lt;/a&gt;.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;&lt;strong&gt;Limites&lt;/strong&gt;&lt;br /&gt;
  &lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt; &lt;a href="#" title="wicket" style="text-decoration: none" &gt;&lt;strong&gt;Wicket&lt;/strong&gt;&lt;/a&gt; stocke beaucoup d’informations en session et il est donc trop lourd pour gérer plusieurs centaine d’utilisateurs simultanés. &lt;/li&gt;
    &lt;li&gt;A l’usage, on se rend compte que l’intégration manuelle avec le &lt;a href="#" title="Java script" style="text-decoration: none" &gt; JavaScript&lt;/a&gt; n’est pas évidente. Toujours ces histoires d’Id générés qui rendent plus compliqué un framework orienté &lt;a href="http://www.blogger.com/post-edit.g?blogID=5977041875295618643&amp;amp;postID=778511194312462278"&gt;Composants.&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt; &lt;strong&gt;&lt;u&gt;GWT Google Web Toolkit&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;p&gt; L’outil de Google est dédié à la présentation. « Il permet de coder 5 fois plus vite la couche graphique Web de son application ». &lt;strong&gt;GWT&lt;/strong&gt; repose sur un modèle en composant. Par exemple, il dispose d’objets Champ texte, Tableau… Chacun de ces composants supporte les &lt;a href="#" title="CSS" style="text-decoration: none" &gt; &lt;strong&gt;CSS&lt;/strong&gt; &lt;/a&gt; et est donc potentiellement skinnable. &lt;/p&gt;
  &lt;div&gt;
    &lt;p&gt;&lt;strong&gt;Avantages :&lt;/strong&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;ul&gt;
      &lt;li&gt;Côté intégration à un modèle de page, il n’y aurait aucun souci. Il suffit de partir du&lt;strong&gt; HTML&lt;/strong&gt; et d’appliquer les styles au composant &lt;a href="http://www.blogger.com/post-edit.g?blogID=5977041875295618643&amp;amp;postID=778511194312462278" title="gwt" &gt;GWT&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;p&gt;&lt;strong&gt;Limites :&lt;/strong&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;ul&gt;
      &lt;li&gt;Manque guidé de bonnes pratiques et de la documentation en général.&lt;br /&gt;
        &lt;div&gt;&lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;Il n’y a que des &lt;strong&gt;composants graphiques « simples »&lt;/strong&gt;. Si l’on veut utiliser des composants plus évolués, il faut soit les coder ou bien se tourner vers des&lt;u&gt; librairies de widgets GWT&lt;/u&gt; Open Source « non Google » (avantage : elles offre des composant telle que agenda facile à intégrer).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;p&gt; &lt;strong&gt;&lt;u&gt;JSF Java Server Faces&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
  &lt;div&gt;
    &lt;p&gt;Java Server Faces est un &lt;strong&gt;Framework&lt;/strong&gt; pour la conception d'interfaces graphiques Web en Java.&lt;/p&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;p&gt;JSF s'attache donc à :&lt;/p&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;ul&gt;
      &lt;li&gt;Faciliter l'écriture d'interface à partir d'une bibliothèque de contrôles.&lt;/li&gt;
      &lt;li&gt;Gérer automatiquement l'état &lt;strong&gt;HTTP&lt;/strong&gt; entre &lt;strong&gt;client et serveur &lt;/strong&gt;(en cas de Postback par exemple)&lt;/li&gt;
      &lt;li&gt;Fournir un modèle simple pour la gestion des évènements coté client et coté serveur&lt;/li&gt;
      &lt;li&gt;Autoriser les créations ou l'enrichissement de composants graphiques utilisateur (custom)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
  
&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8900093511482677774-1101807506185509391?l=jee-best-practices.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jee-best-practices.blogspot.com/feeds/1101807506185509391/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/etude-comparatif-entre-les-framworks-de.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/1101807506185509391?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/1101807506185509391?v=2'/><link rel='alternate' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/etude-comparatif-entre-les-framworks-de.html' title='Etude comparatif entre les framworks de présentation JEE'/><author><name>Jean</name><uri>http://www.blogger.com/profile/15925637809573494664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;D0AEQ3gycSp7ImA9Wx9bEUQ.&quot;'><id>tag:blogger.com,1999:blog-8900093511482677774.post-4994717571855476856</id><published>2011-02-20T01:55:00.000-08:00</published><updated>2011-02-20T01:55:02.699-08:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-02-20T01:55:02.699-08:00</app:edited><title>JSF-Richfaces  , JPA, EJB, avec Seam</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;" &gt;



&lt;p   lang="fr-FR"&gt;Un petit article
pour vous montrer comment créer une application de type CRUD avec
&lt;span style="font-weight: bold;"&gt;JSF 1.2,&amp;nbsp; Jboss-seam EJB et JPA&lt;/span&gt;
ensemble.&lt;/p&gt;
&lt;p   lang="fr-FR"&gt;À la fin de ce petit
  article, vous allez créer une page qui affiche une liste des clients
  existants dans la base de données, modifier les enregistrements et
  une fonction permettant aux utilisateurs d'ajouter un nouveau client
  dans la base.&lt;br&gt;
&lt;/p&gt;

&lt;br &gt;

&lt;ul  &gt;

  &lt;li&gt;&lt;span style="font-weight: bold;"&gt;JSF - Java Server Face&lt;/span&gt; : est
un Framework pour la conception d'interfaces graphiques Web en Java.&lt;/li&gt;
  &lt;li &gt;&lt;span lang="fr-FR"&gt;&lt;span style="font-weight: bold;"&gt;JPA
- Java Persistence API &lt;/span&gt;est l'API de persistance fournie par
JEE5. Cette
API se base en grande &lt;/span&gt;partie sur les concepts apportés par
Hibernate&lt;/li&gt;
  &lt;li&gt;&lt;font style="font-weight: bold;"&gt;&lt;font size="3"&gt;EJB 3 - &lt;/font&gt;&lt;/font&gt;
    &lt;span style="font-weight: bold;"&gt;Entreprise
Java Bean &lt;/span&gt;sont des composants serveurs, permettent de
découpler le code client de l&amp;#8217;interface&lt;/li&gt;
&lt;/ul&gt;

&lt;p  &gt;Le
développement d'applications web basées sur &lt;span style="font-weight: bold;"&gt;J2EE &lt;/span&gt;se résume souvent
à assembler un ou
plusieurs
frameworks (dans notre cas &lt;span style="font-weight: bold;"&gt;JSF&lt;/span&gt;,&lt;span style="font-weight: bold;"&gt;EJB&lt;/span&gt;,&lt;span style="font-weight: bold;"&gt;JPA&lt;/span&gt;
par la suite la librairie des
composantes Richfaces ), parfois pour chaque couche applicative, ces
frameworks étant basés ou no
sur
des standards et bien souvent en provenance de la communauté&lt;span style="font-weight: bold;"&gt; open
source.&lt;br&gt;
&lt;/span&gt;&lt;/p&gt;


&lt;p   &gt;&lt;span style="font-weight: bold;"&gt;Jboss-seam&lt;/span&gt;&amp;nbsp;:
framework d'intégration &lt;span style="font-weight: bold;"&gt;JEE 5&lt;/span&gt;,
&lt;a href="http://seamframework.org/"&gt;&lt;span style="font-weight: bold;"&gt;Seam&lt;/span&gt;&lt;/a&gt;
est livré avec tous les
composants nécessaires au développement d'une &lt;span style="text-decoration: underline;"&gt;application web&lt;/span&gt; et,
en plus, il permet de simplifier grandement les développements grâce
à son modèle de composants unifié.&lt;/p&gt;

&lt;p style="margin-bottom: 0cm; font-weight: bold; font-family: Times New Roman;"&gt;&lt;font size="3"&gt;&lt;u&gt;Préparation
de l'exemple&lt;/u&gt;&lt;/font&gt;
&lt;/p&gt;

&lt;p  &gt;Pour
cette exemple, vous devez dans un premier temps télécharger&lt;/p&gt;
&lt;p  &gt;&lt;a href="http://www.eclipse.org/downloads/" &gt; &lt;strong&gt;Eclipse comme Editeur version  3.5 &lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p  &gt;&lt;strong&gt;Plugin Jboss tools&lt;/strong&gt;&amp;nbsp;pour  la génération de code,wizards...&lt;/p&gt;
&lt;p  &gt; &lt;a href="http://www.jboss.org/jbossas/downloads.html" &gt;&lt;strong&gt;Serveur d'application Jboss&lt;/strong&gt;&lt;/a&gt; j'ai choisi la &lt;u&gt;version 5.1&lt;/u&gt;&lt;/p&gt;
&lt;p  &gt;&lt;a href="http://seamframework.org/Download" &gt; &lt;strong&gt;Seam version 2&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="margin-bottom: 0cm; font-weight: bold; font-family: Times New Roman;"&gt;&lt;font size="3"&gt;&lt;u&gt;Instalation 
de l'exemple&lt;/u&gt;&lt;/font&gt;
&lt;/p&gt;

&lt;/div&gt;


&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8900093511482677774-4994717571855476856?l=jee-best-practices.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jee-best-practices.blogspot.com/feeds/4994717571855476856/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/jsf-richfaces-jpa-ejb-avec-seam.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/4994717571855476856?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/4994717571855476856?v=2'/><link rel='alternate' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/jsf-richfaces-jpa-ejb-avec-seam.html' title='JSF-Richfaces  , JPA, EJB, avec Seam'/><author><name>Jean</name><uri>http://www.blogger.com/profile/15925637809573494664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry gd:etag='W/&quot;DE4FSX06cSp7ImA9Wx9bEUk.&quot;'><id>tag:blogger.com,1999:blog-8900093511482677774.post-5947028660890907454</id><published>2011-02-19T03:02:00.001-08:00</published><updated>2011-02-19T12:21:58.319-08:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-02-19T12:21:58.319-08:00</app:edited><title>Save images into database</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;" &gt;
&lt;p&gt;This exemple show you how to store&lt;strong&gt; byte array&lt;/strong&gt; in data base and retrive it again. &lt;/p&gt;
&lt;p&gt;To do this we need to use the&lt;a href="http://jee-best-practices.blogspot.com/2011/02/image-to-byte-array-and-byte-array-to.html"&gt; Utils Java Class&lt;/a&gt; in my last post ( image to byte array and &lt;strong&gt;byte [] &lt;/strong&gt;to image using java ) and we can chose&lt;u&gt; Postgres&lt;/u&gt; or &lt;u&gt;MySql&lt;/u&gt; data base to store data .&lt;/p&gt;
&lt;p&gt;Many devlopper try to store data in &lt;strong&gt;Varchar&lt;/strong&gt; format or&lt;strong&gt; string&lt;/strong&gt; &lt;strong&gt;varbinary&lt;/strong&gt;,&lt;br /&gt; Saving the byte[] as VarBinary(MAX) is ok. But, the problem comes when retrieving it as &lt;strong&gt;byte array&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In this exemple i will explain how to &lt;h4&gt; switch between images, bytes postgres, and image again using java &lt;/h4&gt;( you can use other data base )&lt;/p&gt;
&lt;p&gt; The first step, we need to make a &lt;strong&gt;Postgres&lt;/strong&gt; databases to store our images data. Make a database called &amp;ldquo;imagedb&amp;rdquo; on your &lt;strong&gt;Postgres or MySQL&lt;/strong&gt;  database, then create a table called &amp;ldquo;image&amp;rdquo; the sql create script : &lt;/p&gt;
&lt;pre class="brush: js"&gt;
CREATE TABLE image
(
  id integer NOT NULL,
  name character varying(255),
  image bytea,
)
&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;
  if you are using &lt;strong&gt;MySql&lt;/strong&gt; change type of image from &lt;strong&gt;bytea&lt;/strong&gt; to &lt;strong&gt;blob&lt;/strong&gt;. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; The id field represent id of &lt;strong&gt;image&lt;/strong&gt;, name field represent name of image, and the dates is field that used to store information when the&lt;strong&gt; image uploaded&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Now we need to use ower Utils.&lt;strong&gt;ImageToByte&lt;/strong&gt; methode in my last post &lt;a href="http://jee-best-practices.blogspot.com/2011/02/image-to-byte-array-and-byte-array-to.html"&gt; from image to bytes &lt;/a&gt;&lt;/p&gt;
&lt;pre class="brush: js"&gt;
public static byte [] ImageToByte(File file) throws FileNotFoundException{
        FileInputStream fis = new FileInputStream(file);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        try {
            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);      
                System.out.println("read " + readNum + " bytes,");
            }
        } catch (IOException ex) {
        }
        byte[] bytes = bos.toByteArray();
     
     return bytes; 
    }
&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;
  Next step is to make a JDBC connection, i prefer to use JPA but now just to show you how we can insert byte to database &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;To do this i created two class: the first one is to create&lt;strong&gt; connection to data base&lt;/strong&gt; named ConnectDB.java, the second one for&lt;strong&gt; SQL Query&lt;/strong&gt; and finaly we need to create ower main methode for test &lt;/p&gt;
&lt;pre class="brush: js"&gt;
import java.sql.Connection;
import java.sql.DriverManager;

public class ConnectDB {

 Connection mySqlConnection;
 String URL = "jdbc:postgresql://localhost:5432/imagedb";
 String pwd = "root";
 String user = "postgres";

 public Connection getConnection() {

  try {
   Class.forName("org.postgresql.Driver");

  } catch (Exception e) {
   System.out.println("Driver Problem");
   e.printStackTrace();
  }
  try {
   if (mySqlConnection == null) {
    mySqlConnection = DriverManager.getConnection(URL, user, pwd);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return mySqlConnection;
 }

}
&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;
Don't forget to add the JDBC jar into your class path.
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The second Java Class is the Class used to execute SQL Query for insert and select Data :&lt;/p&gt;
&lt;pre class="brush: js"&gt;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.*;

import java.sql.Statement;

public class ConnectionBdImage {

 public byte[] getImage(int id) {
  byte[] byteImg = null;
  bd connect = new bd();
  Connection connection = null;
  try {
   connection = connect.getConnection();
   // String byteImg="";
   PreparedStatement ps = connection
     .prepareStatement("SELECT image FROM image WHERE id = ?");
   ps.setInt(1, id);
   ResultSet rs = ps.executeQuery();
   while (rs.next()) {
    byteImg = rs.getBytes(1);
    // use the data in some way here
   }
   rs.close();
   ps.close();

   return byteImg;
  } catch (Exception e) {
   // TODO: handle exception
   return null;
  }

 }

 public void addImage(byte[] img, int id) {
  bd connect = new bd();
  Connection connection = null;
  try {
   connection = connect.getConnection();

   Statement statement = connection.createStatement();

   PreparedStatement ps = connection
     .prepareStatement("INSERT INTO image VALUES (?, ?, ?)");
   ps.setInt(1, id);
   ps.setBytes(2, img);
   ps.setString(3, "test");

   ps.executeUpdate();
   ps.close();
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   try {
    connection.close();

   } catch (Exception e) {
    // TODO: handle exception
   }
  }

 }
    
&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;
getImage methode is to get image from &lt;strong&gt;data base&lt;/strong&gt; and addImage is to &lt;strong&gt;store it into&lt;/strong&gt; DB.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Finaly we need main methode to store Data : &lt;/span&gt;&lt;/p&gt;
&lt;pre class="brush: js"&gt;
public class ConvertImage {   
 
    public static void main(String[] args) throws FileNotFoundException, IOException {
     
     ConnectionBdImage bd = new ConnectionBdlogin();
     
     String fileSource = "C:/imgSource/image.jpg";
     String fileDestination = "C:/imgDestination/destination.jpeg";
     
     try {
      
      byte [] byteImage = Utils.ImageToByte(new File(fileSource));
      
      bd.addImage(byteImage, 1);
      System.out.println(org.postgresql.util.Base64.encodeBytes(bd.getImage(1)));
     Utils.byteToImage(bd.getImage(1), new File(fileDestination));
  } catch (Exception e) {
   e.printStackTrace();
  }      
    }
     
}
&lt;/pre&gt;
&lt;p&gt;Using the above steps you can &lt;strong&gt;retrieve and display&lt;/strong&gt; the image from the &lt;strong&gt;database&lt;/strong&gt; and store it into file or display to the web page.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8900093511482677774-5947028660890907454?l=jee-best-practices.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jee-best-practices.blogspot.com/feeds/5947028660890907454/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/save-images-into-database.html#comment-form' title='1 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/5947028660890907454?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/5947028660890907454?v=2'/><link rel='alternate' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/save-images-into-database.html' title='Save images into database'/><author><name>Jean</name><uri>http://www.blogger.com/profile/15925637809573494664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry gd:etag='W/&quot;CU4EQX44cCp7ImA9Wx9bEU0.&quot;'><id>tag:blogger.com,1999:blog-8900093511482677774.post-8135532113196044600</id><published>2011-02-18T14:23:00.001-08:00</published><updated>2011-02-19T00:25:00.038-08:00</updated><app:edited xmlns:app='http://www.w3.org/2007/app'>2011-02-19T00:25:00.038-08:00</app:edited><title>Image to byte array and byte array to image</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Il existe déjà des milliers d'exemple sur internet sur comment convertire&lt;br /&gt;
une image vers un tableau des &lt;span style="font-weight: bold;"&gt;byte []&lt;/span&gt; en &lt;span style="font-weight: bold;"&gt;java &lt;/span&gt;et vis versa, récement j'ai eu l'occasion de travailer sur un petit projet qui&amp;nbsp; m'oblige a convertire une image vers un &lt;span style="font-weight: bold;"&gt;tableau de bytes&lt;/span&gt;, stocker dans une base des données et de récuperer l'image par la suite.&amp;nbsp;Ma recherche sur internet n'etait pas satisfaisante vu que j'arrive pa&lt;br /&gt;
a convertire les images de n'importe types &lt;span style="font-weight: bold;"&gt;gif&lt;/span&gt;, &lt;span style="font-weight: bold;"&gt;tiff&lt;/span&gt;, &lt;span style="font-weight: bold;"&gt;jpeg&lt;/span&gt;, &lt;span style="font-weight: bold;"&gt;jpg&lt;/span&gt;, &lt;span style="font-weight: bold;"&gt;png&lt;/span&gt; ...&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;This &lt;b&gt;Java Class&lt;/b&gt; contains two methode for how to convert&amp;nbsp;image png, tiff, jpeg, jpg, gif to an array of &lt;b&gt;byte []&lt;/b&gt; in &lt;b&gt;Java.&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;b&gt;&lt;/b&gt;The first one take the path of file " c:/file_path/image.png " and return &lt;b&gt;array of bytes&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
&lt;pre class="brush: js"&gt;public static byte [] ImageToByte(File file) throws FileNotFoundException{
        FileInputStream fis = new FileInputStream(file);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        try {
            for (int readNum; (readNum = fis.read(buf)) != -1;) {
                bos.write(buf, 0, readNum);      
                System.out.println("read " + readNum + " bytes,");
            }
        } catch (IOException ex) {
        }
        byte[] bytes = bos.toByteArray();
     
     return bytes; 
    }
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;This &lt;b&gt;Second one &lt;/b&gt;is&lt;b&gt; to convert&lt;/b&gt; back from bytes array &lt;b&gt;byte []&lt;/b&gt; to &lt;u&gt;jpeg image&lt;/u&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
&lt;pre class="brush: js"&gt;public static void byteToImage(byte [] bytes,File imageFile) throws IOException{
     
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        Iterator readers = ImageIO.getImageReadersByFormatName("jpeg");
 
        ImageReader reader = (ImageReader) readers.next();
        Object source = bis; // File or InputStream, it seems file is OK
 
        ImageInputStream iis = ImageIO.createImageInputStream(source);

        reader.setInput(iis, true);
        ImageReadParam param = reader.getDefaultReadParam();
 
        Image image = reader.read(0, param);
        //got an image file
 
        BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
      
        Graphics2D g2 = bufferedImage.createGraphics();
        g2.drawImage(image, null, null);
 
        ImageIO.write(bufferedImage, "jpeg", imageFile);
        //"jpeg" is the format of the image
        //imageFile is the file to be written to.
 
        System.out.println(imageFile.getPath());
     
 
    }
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;Our &lt;b&gt;Java Utils Class&lt;/b&gt; is now :&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: js"&gt;import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;


public class Utils {

 public static byte [] ImageToByte(File file) throws FileNotFoundException{
      //code of ImageToByte
     return bytes; 
    }
    
    public static void byteToImage(byte [] bytes,File imageFile) throws IOException{
      // code of byteToImage
    }
}
&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Simple &lt;b&gt;main java class&lt;/b&gt; for test :&lt;br /&gt;
&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class="brush: js"&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;public static void main(String[] args) {
     
    try {
       byte [] bytes = Utils.ImageToByte(new File("/home/path_source/image.png"));
      Utils.byteToImage(bytes,new File("/home/path_destination/destination_image.png"));
  }
     catch (Exception e) {
   e.printStackTrace();                                          
     }       
    }
&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-style: normal;"&gt;&lt;br /&gt;
In other post we will use this class to store byte into database ans show picture into html&amp;nbsp; &lt;/span&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8900093511482677774-8135532113196044600?l=jee-best-practices.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jee-best-practices.blogspot.com/feeds/8135532113196044600/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/image-to-byte-array-and-byte-array-to.html#comment-form' title='2 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/8135532113196044600?v=2'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8900093511482677774/posts/default/8135532113196044600?v=2'/><link rel='alternate' type='text/html' href='http://jee-best-practices.blogspot.com/2011/02/image-to-byte-array-and-byte-array-to.html' title='Image to byte array and byte array to image'/><author><name>Jean</name><uri>http://www.blogger.com/profile/15925637809573494664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>