Willy Loman is the main character in Miller's Death of a Salesman, and Hamlet is the main character in Shakespeare's play of the same name.
Superficially, both seem to have little in common. Both men are struggling to survive in a life that has become overwhelming for each. Willie is living in the past, and finds that the world is a place he no longer recognizes. Hamlet, upon discovering that his father has been murdered, also sees the world as a foreign place that is in great part unknown to him. Both men "see dead people" that were dear to them in life: Willy sees his dead brother Ben, and has conversations with him—though these are probably delusions. Hamlet sees the ghost of his dead father, and based upon the time it was written, the presence of the supernatural in the play was not out of place: the audience would have believed it was real.
However, the men are very different in many ways. Willy is married with two children; Hamlet is single. Willy is a workingman, while Hamlet is a prince. Willy is struggling to get by in a world that has changed faster than he can keep up. Hamlet has been charged by his dead father's ghost to avenge his murder.
But, both characters develop based upon major conflicts they face. In each case, these men fail to survive the struggles they encounter. One quote from Miller's play seems to capture the essence of the difficulty in life of each man:
Sometimes...it's better for a man just to walk away.
But if you can't walk away?
I guess that's when it's tough.
Willie is unable to walk away from a career that has moved forward without him. In the same way, Hamlet's father exacts his son's promise to make Claudius pay for murdering Old Hamlet. The act of revenge will not bring Old Hamlet back. In fact, it ultimately destroys each relationship Hamlet has, costing him his life—simply because Hamlet believes he does not have the option of walking away.
Both men struggle to survive, but suicide is an important element in the lives of each character. Willy attempts suicide several times, however it is only at the play's end that he is finally successful. Hamlet also considers suicide, but his belief that God has outlawed such an act stops him from carrying out his wish to end his life.
O, that this too too solid flesh would melt,
Thaw and resolve itself into a dew!
Or that the Everlasting had not fix'd
His canon 'gainst self-slaughter! O God! God! (I.ii.132-135)
As each man moves forward in the play, his attempts to adapt to the heartaches he faces become overwhelming, leading each to his destruction. Willy is increasingly involved in the past, speaking to his dead brother and unable to connect with his wife, sons or friends.
Hamlet is in the same circumstance: he alienates Ophelia and Laertes; he has accidentally killed Polonius; his relationship with is mother is mended, but he has made Claudius suspicious. By the end, Willy feels completely cut off from those closest to him. For Hamlet, Claudius (in the end) kills almost everyone Hamlet has ever cared about, either by poisoning them or causing the deterioration of Hamlet's good judgment (which results in Polonius' death and Ophelia's loss of sanity and, later, her death).
Willy Loman and Hamlet seem to embrace death. Willy succeeds after repeated attempts to take his life. Hamlet has grown weary of life, and, like Willy, does not rage against the end of his life as one might suspect. Dramatically, both are tragic figures that die.