Aim: A web application that takes name and age from an HTML page. If the age is less than 18, it should send a page with “Hello , you are not authorized to visit this site” message, where should be replaced with the entered name. Otherwise it should send “Welcome to this site” message.

File: login7.html

<form name="login" method="post" action="hello7.jsp">
    <table width="370" border="1" align="center" style="background: silver;">
        <tr height="25">
            <th colspan="4" align="center">User Login</th>
        </tr>
        <tr>
            <td>User Name</td>
            <td><input type="text" name="uname" required></td>
        </tr>
        <tr>
            <td>Age</td>
            <td><input type="number" name="age" required></td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <input type="submit" name="ok" value="Submit">
            </td>
        </tr>
    </table>
</form>
        
File: hello7.jsp

<%@page import="javax.servlet.RequestDispatcher" %>
<%
    String uname = request.getParameter("uname");
    session.setAttribute("uname", uname);
    int age = Integer.parseInt(request.getParameter("age"));

    if (age < 18) {
        out.println("<h4 align='center'>Hello " + uname + ", you are not authorized to visit this site.</h4>");
        RequestDispatcher rd = request.getRequestDispatcher("login7.html");
        rd.include(request, response);
    } else {
        out.println("<h2 align='center'>Hello " + uname + ", Welcome to this site!</h2>");
    }
%>
        
Output:

login.jsphello.jsp (1)submit.jspwelcome.jsp

;