Results.jsp can be used?

Oct 9, 2009 at 1:05 PM

Hi

I am doing a j2ee project in eclipse and I would like to use flexbox. But I am unable to use the results.aspx. So what I did was I typed the format of JSON in string and tried to return it. Its not working :(

My flex.jsp

<%@ 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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" />  
<script type="text/javascript" src="js/jquery.flexbox.min.js" /><!-- or use jquery.flexbox.js for debugging -->  
<link type="text/css" rel="stylesheet" href="css/jquery.flexbox.css" />
    <script type="text/javascript">  
        $.ready(function() {  
            // results.aspx is the page that returns json data in the expected format  
            $('#ffb4').flexbox('results.jsp');   
        });  
    </script>  
</head>
<body>
    <div id="ffb4">
      
    <input id="ffb4_input" autocomplete="off" style="padding: 2px; width: 200px;"/>
    </div>  
</body>
</html>

This is my results.jsp

<%@ 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">

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
         int i=1;

        String s="kjkjkjhkjhk";
    String a="{\"results\":[{\"id\":"+i+",\"name\":\""+s+"\"}]}";
    System.out.println(a);

    %>
    <%=a%>

</body>
</html>

Please guide me. I am sorry if I have made blunders here but I am new to jQuery :(

I have included the necessary css,js and images. My output is a textbox which does nothing when I type on it :'(

Coordinator
Oct 9, 2009 at 6:05 PM

The primary issue is that your jsp page is outputting html, and you want it to output pure JSON.

Here is a very simple example of a JSP page which outputs pure JSON (using your code snippet):

<%@ page contentType="application/json" %>
<%@ page pageEncoding="UTF-8" %>
<%
  int i=1;
  String s="kjkjkjhkjhk";
  String a="{\"results\":[{\"id\":"+i+",\"name\":\""+s+"\"}]}";
  System.out.println(a);
%>

Of course, you would be best off to use a class like JSONObject to build up your JSON data in a safer and more maintainable way:

http://json.org/javadoc/org/json/JSONObject.html

Good luck!