views:

22

answers:

1

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!

A: 

Your JSP is the view here. Your User entity is the model here. What's missing form the "MVC"? Right, the controller is missing. You need to develop (or introduce) a controller yet. Is this homework? Then probably just a simple Servlet is enough. But if this is the real work, then I recommend to have a look for a real MVC framework to ease all the work, for example Sun JSF (JavaServer Faces).

See also:

BalusC