Slip No 14 Q A

Write a JSP program to accept Name and Age of Voter and check whether he is eligible for voting or not.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<html>
<head>
    <title>Voter Eligibility Check</title>
</head>
<body>

<h2>Voter Eligibility Check</h2>

<form method="post">
    Name:
    <input type="text" name="name" required><br><br>

    Age:
    <input type="number" name="age" required><br><br>

    <input type="submit" value="Check Eligibility">
</form>

<%
    String name = request.getParameter("name");
    String ageStr = request.getParameter("age");

    if (name != null && ageStr != null) {
        int age = Integer.parseInt(ageStr);

        if (age >= 18) {
%>
            <p style="color:green; font-size:16px;">
                Hello <b><%= name %></b>, you are <b>eligible</b> for voting.
            </p>
<%
        } else {
%>
            <p style="color:red; font-size:16px;">
                Hello <b><%= name %></b>, you are <b>not eligible</b> for voting.
            </p>
<%
        }
    }
%>

</body>
</html>
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top