I am facing problem when comparing 2 strings values using C:When tag
I am trying as follow
<c:when test="${dbUserName eq uName}">
Where,
dbUserName = “sohail”
. It is fetching value from db column
uName = “test”
. This is actually input value on login page
But comparison always giving result true…
Here is complete code
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<HTML>
<body>
<c:set var='uName' value="${param.username}"/>
<c:set var='uPassword' value="${param.password}"/>
<sql:setDataSource var="db" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test" user="root" password="sohail"/>
<sql:query var="query1" dataSource="${db}"
sql="select * from login where loginID = '${uName}'">
</sql:query>
<c:forEach var="row" items="${query1.rows}">
<c:set var='dbUserName' value="${row.loginID}"/>
<c:set var='dbUserPassword' value="${row.password}"/>
</c:forEach>
<c:out value="${uName}"/>
<c:out value="${row.loginID}"/>
<c:out value="${row.password}"/>
<c:choose>
<c:when test="${dbUserName eq uName}">
<c:redirect url="profile1.jsp"/>
</c:when>
<c:otherwise>
<c:redirect url="checlLogin.jsp"/>
</c:otherwise>
</c:choose>
</body>
</html>
Kindly suggest how can I fix comparison problem?
Hi Affe,
Thanks, you're right. The problem has been resolved
i just modified query as follow and it is working fine
<sql:query var="query1" dataSource="${db}"
sql="select * from login">
</sql:query>