Dynamic Web Site

Junghoo Cho

cho@cs.ucla.edu

Dynamic User Interaction

HTML Form

HTML Form Interaction

HTML Form: <form>

HTML Form: <input>

Input Encoding: GET vs POST

Input Types

Uploading a File: file Type

MIME: multipart/form-data

Coding Dynamic Web Server

Programmatic Approach

Template Approach

Separating Code from Page

Model-View-Controller (MVC) Pattern

MVC Pattern: Data

MVC Pattern: Presentation

MVC Pattern

MVC Example: Controller

/*  CONTROLLER */
protected void doGet(HttpServletRequest request, 
                        HttpServletResponse response)
    throws ServletException, IOException
{
    // retrive data
    user = getUser('id_34');

    // complex application logic here

    // dispatch data model to the view
    request.setAttribute("user_name", user.name);
    request.getRequestDispatcher("/index.jsp").forward(request, response);
}

MVC Example: Model

/*  MODEL  */
User getUser(String userid)
{
    // retrieve and return the user data
}

MVC Example: View

/* VIEW */
<html>
<head><title>Demo</title></head>
<body>Hello, <%= request.getAttribute("user_name") %></body>
</html>

Special Tag Libraries

Four Layers of Web site

What We Learned