Model 1 Coverage: not covered in class

Bottom line: For this class, you can skip the Model-1 related material:

Guiding principle: We are doing MVC Model 2, which has a servlet to accept UI, but it is possible to live without servlets (except JSP servlets of course). That's "Model 1". Then everything for presentation is done in JSP, including interpreting incoming parameters.

For Model 1 JSP-only webapps we need a pure JSP way to set up the user object/bean to allow ${user.firstName} to work. EL itself does not provide a way. Here it is, on pg. 187 of Chap 6:

<jsp: useBean id=”user” class=”” scope=”request”  />

However, the bean set up this way has just whatever the no-args constructor sets up.

A fancier useBean ispossible, with nested <jsp:setProperty…> to set  properties of the new bean.  These setProperties are not executed if the bean already exists.

<jsp:setProperty…> can also  be used at the top level to set a property in a bean held as a session or request variable. See pg. 189

Accessing request parameters in EL: it’s easy with EL’s implicit object “param”

In EL, have implicit var “param” with properties ßà params

In basicjsp of my UNIX tomcat

testform.jsp (could be .html)

<form action=”getparam.jsp” method=”post”>
       enter something:
       <input type=”text” name=”formitem”/></p>
       <p><input type=”submit”/></p>

Click on submit, HTTP POST, with request parameter formitem=hello in the POST body


Your input was ${param.formitem}

POST: sends params in the body of the message to the server

Tomcat decodes params from GET or POST & puts them in request parameters

EL Implicit object paramValues is useful for gaining access to multiple params of the same name.

The example here would have a URL with ?emailAddress=oneval&emailAddress=anotherval, two params both named emailAddress (actually hidden away in the POST body here, because the form has method=”post”)

Pg. 257, how to access these: ${paramValues.emailAddress[0]} and  ${paramValues.emailAddress[1]}  --seeing arrays in use in EL. Here paramValues.emailAddress is itself an array, or works like an array.

However, we don’t need param, paramValues for pure MVC apps, because the servlet interprets incoming parameters.