A study of collisionless external shocks in gamma-ray bursts is presented. The shock structure, electromagnetic fields, and process of electron acceleration are assessed by using a self-consistent 3D particle-in-cell simulation. In accordance with hydrodynamic shock systems, the formed shock is composed of a forward and reverse shock separated by a contact discontinuity. The establishment of the shock transitions is controlled by the ion Weibel instability. The ion filaments are sources the strong transversal electromagnetic fields at the two sides of the double shock structure with a length about 30-100 ion skin depths. In regard to the electrons, they are heated up to a maximum energy e_ele ≈ √e_b (normalized to the total incoming energy). Moreover, the jet electrons behind the reverse shock are trapped due to the presence of an ambipolar electric field accompanying with reflection by the strong transversal magnetic fields in the shocked region. In a similar process to the shock surfing acceleration, they endure a drift motion and acceleration by the transversal electric fields of ion filaments in the plane perpendicular to the shock propagation direction. The accelerated jet electrons finally are convected back to the upstream.