I am unsure of how to access a persistence entity from a JSP page?

Posted by pharma_joe on Stack Overflow See other posts from Stack Overflow or by pharma_joe
Published on 2010-05-19T08:20:55Z Indexed on 2010/05/19 12:10 UTC
Read the original article Hit count: 178

Filed under:
|
|

Hi,

I am just learning Java EE, I have created a Persistence entity for a User object, which is stored in the database. I am now trying to create a JSP page that will allow a client to enter a new User object into the System. I am unsure of how the JSP page interacts with the User facade, the tutorials are confusing me a little.

This is the code for the facade:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Add User to System</title>
</head>
<body>
    <h2>Add User</h2>
    <h3>Please fill out the details to add a user to the system</h3>
    <form action="">
        <label>Email:</label>
        <input type="text" name="email"><br />
        <label>Password:</label>
        <input type="password" name="name"><br />
        <label>Name:</label>
        <input type="text" name="name"><br />
        <label>Address:</label>
        <input type="text" name="address"><br />
        <label>Type:</label>
        <select name="type">
            <option>Administrator</option>
            <option>Member</option>
        </select><br />
        <input type="submit" value="Add" name="add"/>
        <input type="reset" value="clear" />
    </form>
</body>

This is the code I have to add a new User object within the User facade class:

@Stateless
public class CinemaUserFacade {
    @PersistenceContext(unitName = "MonashCinema-warPU")
    private EntityManager em;

public void create(CinemaUser cinemaUser) {
    em.persist(cinemaUser);
}

I am finding it a little difficult to get my head around the whole MVC thing, getting there but would appreciate it if someone could turn the light on for me!

© Stack Overflow or respective owner

Related posts about java-ee

Related posts about persistence