views:

153

answers:

1

Hi,

I am getting following error when I try to perform login validation using JSTL Custom Tags
org.apache.jasper.JasperException: /checlLogin.jsp(12,38) Unterminated <sql:setDataSource tag

Please find below software specifications I have
- I have placed JSTL.jar and Standard.jar at CATALINE_HOME...\WEB-INF\lib
- Working with server: Apache Tomcat/6.0.29 - Servlet Specification: 2.5 - JSP version: 2.1 - MySQL Sever: 5.1.47

<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt; 
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%&gt;  


<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", "root", "sohail"/> 
<sql:query var="query1"  dataSource="${db}"
sql="select * from login where loginID == '${uName}'">
</sql:query>  
<c:forEach   var="row" tems="${sqlQuery.rows}">
<c:set var='dbUserName' value='${row.username}'/>  
<c:set var='dbUserPassword' value='${row.password}'/>  
</c:forEach>
<c:choose>
    <c:when test="${dbUserName eq uName}">
    <c:redirect url="http://stackoverflow.com/"/&gt;
    </c:when>
    <c:otherwise>
    <c:redirect url="http://stackoverflow.com/"/&gt;
    </c:otherwise>
</c:choose>

Kindly suggest where I am wrong?

I was learning JSP using JAVA Code but then I came to know that JAVA Code is not recommended in JAVA. So eventually I have to work in JSTL.

+1  A: 

The tag syntax is invalid. Those commas doesn't belong there. You need to set the username and password each as an attribute as per the sql:setDataSource tag documentation.

<sql:setDataSource var="db" driver="com.mysql.jdbc.Driver" 
    url="jdbc:mysql://localhost:3306/test" user="root" password="sohail" /> 

That said, I don't want to disappoint you, but it is also not recommended to use JSTL SQL taglibs. It should only be used for quick prototyping / demo. But in real practice you should be doing all this DB interaction jobs in standalone Java classes which you can then import in your servlet and access/display in your JSP. Also all business/domain jobs should be (indirectly) done by a servlet. This gives you the benefits of much better reusability, maintainability and testability.

To be clear: using JSTL instead of scriptlets is perfectly fine, you should only avoid the sql and xml taglibs as they are intented for quick prototyping only. The core, fn and fmt taglibs are fine.

See also:

BalusC