0

I have been thrown into converting some JSP scriptlets items to JSTL expression items.

I am pulling 1 record of the database to for the end user to view before deleting it. It is pulled by it's row id.

"id" is passed from another form like:

<%
    String id = request.getParameter("id");
    RoleValidatorApprover r = RoleValidatorApproverDao.getRecordById(Integer.parseInt(id));
%>  

The Java to "getRecordById" is:

while (rs.next()) {
    record = new RoleValidatorApprover();
    record.setId(rs.getInt("id"));
    record.setAccountid(rs.getString("accountid"));
    record.setFirstname(rs.getString("firstname"));
    // etc.
}
return record;

The JSP scriptlet works and it uses the following format to fill in the form fields with values:

<input type="text" name="id" value="<%=r.getId()%>" />
<input type="text" name="accountid" value="<%=r.getAccountid()%>" />
<input type="text" name="firstname" value="<%=r.getFirstname()%>" />

Those display in the form fine and dandy but I have no idea how to convert that to JSTL. I looked at "c:out" but still not sure.

  • The thing is, you shouldn't care about the ID and execute a SQL query from the JSP. That's the role of the controller, written in Java. Then the controller should store the record in a request attribute, and the view should display the record. c:out is indeed tha tag to use to display values and make sure HTML special characters in those values are properly escaped. – JB Nizet Apr 11 '18 at 20:58
  • Thanks for that answer. I am "inheriting" this small app, so I guess I need to rethink how it is doing what it is doing. – Robert X Apr 12 '18 at 13:26

0 Answers0