I am trying the below JSP EL code for comparing input password inside a Login page.
The password variable comes from the text box and has been set appropriately; there is no error in that part (or at least it seems so!).
But when I try to compare the password with the string "admin" (the valid password). it always returns false for eq
and always returns true for ne
Here is the FULL code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL Core Based Login</title>
</head>
<body>
<form action="CoreBasedLogin.jsp">
Name: <input type="text" name="name" /> <br> <br>
Password: <input type="text" name="password" /> <br> <br>
<input type="submit" value="Login"/>
</form>
<%
String name = request.getParameter("name");
String password = request.getParameter("name");
%>
<c:set var="name" value="<%=name%>"/>
<c:set var="password" value="<%=password%>"/>
<c:if test="${password ne null}">
<c:if test="${password eq 'admin'}">
<c:out value="Login Successful"></c:out>
</c:if>
<c:if test="${password ne 'admin'}">
<c:out value="Login Failed"></c:out>
</c:if>
</c:if>
</body>
</html>
I know the == operator and eq operator both do the same thing. But I can't get this code to work.
Please advise how to proceed.
TIA :)
<c:out value="${password}"/>
${password}