0

I am facing problem in accessing the jsp "core tag" in jsp "sql tag" for a query.

Code :

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %> 

<sql:setDataSource
    var="myDS"
    driver="org.postgresql.Driver"
    url="jdbc:postgresql://localhost:xxxx/xyz"
    user="xyz" password="test123"
/>
<% String user_Email = session.getAttribute("email").toString(); 
   out.println("Email = "+ user_Email); %>
  <c:set var="emailid" value= "${user_Email}"/>

<sql:query var="listUsers"   dataSource="${myDS}">

    SELECT * FROM developer_apikey_registration where email_id = ?  ;
    <sql:param value="${emailid}"/>


</sql:query>

I am not able to get the email value here. Although I checked that it is coming correctly in the session attribute.

Please help me in this regard. I am new to JSP Thanks in Advance.

Jeet
  • 761
  • 3
  • 10
  • 27

2 Answers2

0

Try this code

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %> 
<sql:setDataSource
    var="myDS"
    driver="org.postgresql.Driver"
    url="jdbc:postgresql://localhost:xxxx/xyz"
    user="xyz" password="test123"
/>
  <c:set var="emailid" value= "${sessionScope[user_Email]}"/>
<sql:query var="listUsers"   dataSource="${myDS}">
    SELECT * FROM developer_apikey_registration where email_id = ?  ;
    <sql:param value="${emailid}"/>
</sql:query>

Hope this helps !!

Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • Checked, still not working.... Same issue, I can't see the email getting assigned to the sql param. I don't see any error as well in the server. – Jeet Mar 25 '14 at 05:57
  • Any exceptions . Please check you have anything like this `<%@ page session="false" %>` directive in your jsp – Santhosh Mar 25 '14 at 05:59
  • No, if I will use that then how I will get the session.getAttribute("email") value in the above code.... Nothing like that is mentioned. By default it is true. – Jeet Mar 25 '14 at 06:01
  • No even in that case it works for getAttribute . [Check here](http://stackoverflow.com/questions/4730790/problem-with-session-attributes-in-jsp-el-using-spring-mvc) – Santhosh Mar 25 '14 at 06:04
  • Next thing to check whether EL is working for you , check printing `${sessionScope[user_Email]}"` this – Santhosh Mar 25 '14 at 06:07
  • How to print "${sessionScope[user_Email]}" ? I wrote it in <%= %> tag within double quote. It prints ${sessionScope[user_Email]}. Without double quote, I get error in compilation – Jeet Mar 25 '14 at 06:14
  • The code edited above should work as i have tried it in my local machine . what error you got ? – Santhosh Mar 25 '14 at 06:17
  • No, not working, I checked, There is some issue with accessing the value in sql tag. Either the assignment is not proper or may the jar I attached have some issue..... It is still working fine with static value. There is no error I can see in the server, So not able to debug as well... – Jeet Mar 25 '14 at 06:31
  • you may try clean and build or re-install your jar files – Santhosh Mar 25 '14 at 06:39
  • Nothing helped till now... Thanks for support, Leaving the topic here... Will debug in eve. Issue still not resolved. I don't see any error, But sure there is issue with the assignment to the c: var. – Jeet Mar 25 '14 at 07:07
0
    <%String pkgName=null;%>
    <%String apiKey=null;%>
    <% String user_Email = session.getAttribute("email").toString(); 
       String email = null;
     if(session.isNew())
        {
             RequestDispatcher rdp=request.getRequestDispatcher("index.jsp");
             rdp.forward(request, response);
        }
    %>
   <%= user_Email %> // To check if email is not null

    <div align="center">
    <table border="1" cellpadding="5">
        <caption><h2>List of users</h2></caption>
        <tr>
            <th>Email</th>
            <th>Package Name</th>
            <th>API Key</th>
            <th> Operation </th>
        </tr>


  <%
       try
       {
         Connection con=DbConn.getConnect();
         Statement st=con.createStatement(); 
         String q1="select * from  developer_apikey_registration where email_id ='"+user_Email+"'";
         ResultSet rs1=st.executeQuery(q1);

         while(rs1.next())
                {

                   email = rs1.getString("email_id");
                   pkgName = rs1.getString("package_name");
                   apiKey = rs1.getString("apikey");
                   %>

                   <tr>
                <td><%=email%></td>
                <td><%=pkgName%></td>
                <td><%=apiKey%></td>
                <td><input type ="button" name="editBtn" id ="edtBtn" value="Edit">
        <input type ="button" name="deleteBtn" id ="delBtn" value="Delete"> </td>
            </tr>
    <%               
                }

       }  
       catch(Exception e)
               {
                e.printStackTrace();
           }


    %>

   </table>
</div>
Jeet
  • 761
  • 3
  • 10
  • 27