0

I'm trying to show the data from postgresql to slickgrid. However, in javascript for loop, I can't retrieve right values from JSP expression. How can I do it?

conn = dataSource.getConnection();
        stmt = conn.createStatement();
        rs  = stmt.executeQuery("SELECT host_name,username,key_value,updated from pass_table");
        while(rs.next()) {
            hostname.add(rs.getString(1));  
        } 
    } catch (Exception e) {
        out.println("<br /><font color='red'><strong>SQL Exception: " + e + "</strong></font><br/>");
        }
        %>


      $(function () {
       var data = [];
        for (var i = 0; i < 2; i++) {
          data[i] = {
            //title: "Task " + i
            title: "<%= hostname.get(i)%>"  <===this part
            //title: "${row.host_name}" + i
         };
        }


        grid = new Slick.Grid("#myGrid", data, columns, options);
      })
    </script>
1
  • this question is possible duplicate check out this jsp-js i think you have the problem with i in this <%= hostname.get(i)%> code. Commented Nov 2, 2015 at 6:46

2 Answers 2

1

try this ,

$(function () {
    var data =[]; 
     <%
        for(int i = 0; i < 2; i++) {
        %>
       data[<%=i%>] ={
              title:"<%= hostname.get(i)%>"
        <%
        };
        %>
     };

     grid = new Slick.Grid("#myGrid", data, columns, options);
          })
Sign up to request clarification or add additional context in comments.

2 Comments

this error below occured when I executed it An error occurred at line: 107 in the jsp file: /SlickGrid-master/examples/example1-simple.jsp i cannot be resolved to a type 104: <% 105: for(int i = 0; i < 2; i++) { 106: %> 107: data[<%i%>] ={ 108: title:"<%= hostname.get(i)%>" 109: <% 110: }
@Hyunseung sorry I forgot equal sign and semicolon.
0

I replaced code as below and it works. Thank you so much Hashy!!

$(function () {
    var data =[]; 
     <%
        for(int i = 0; i < 2; i++) {
        %>
       data[<%=i%>] ={title:"<%= hostname.get(i)%>"};
     <%
     };
%>
     grid = new Slick.Grid("#myGrid", data, columns, options);
          })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.