In this paper the authors mainly discuss the inverse eigenvalue problem of Hamiltonian matrices. The necessary and sufficient conditions of solvability for the problem are conducted. And the general form of solutions is presented. Further, the authors research the optimal approximation solution to any given matrix, prove that such solution is unique and provide the formula to compute it. Some examples are given to demonstrate that the results are right and the algorithm is feasible.