Preparing Error Reports for Failed Logins

The following steps add functions to the login.jsp page for displaying error messages when a user login fails. The scriptlets and expression used in the login.jsp page set up a variable to hold any error message. If the user login fails, the connection method sets a message for the session. This page checks to see if there is such a message, and if present, it displays the message.

  1. With the login.jsp page open in the Visual Editor, position the cursor after the text on this page. Then, from the JSP page of the Component Palette, drag and drop the Scriptlet element from the palette onto the page.
  2. In the Insert Scriptlet dialog box, enter the following code:
        String loginerrormsg = null;
        loginerrormsg = (String) session.getAttribute("loginerrormsg");
        if (loginerrormsg != null) {
    
  3. Add another scriptlet in exactly the same way, and this time enter only a single closing brace (}) in the Insert Scriptlet dialog box.
  4. Place the cursor between the two scriptlets and press Enter to create a new line. Apply the Heading 4 style to the new line.
  5. With the cursor still on the new line, in the JSP page of the Component Palette, click Expression.
  6. In the Insert Expression dialog box, enter loginerrormsg.
  7. To see the code that has been added to your login.jsp page, below the Visual Editor, select the Source tab. The code should appear as follows:
    <% 
        String loginerrormsg = null;
        loginerrormsg = (String) session.getAttribute("loginerrormsg");
        if (loginerrormsg != null) {
    %>
    <h4>
      <%=  loginerrormsg %>
    </h4>
    <% 
    }
    %>
    

Before continuing with the following sections, return to the design view of the page by selecting the Design tab.