Can anyone give me an example of how to return the following json simply from a jsp without any external libraries (except the ones that come standard with Oracle Java)?
[
{"label":"item 1", "value":"item 1", "id": 1},
{"label":"item 2", "value":"item 2", "id": 2},
{"label":"item 3", "value":"item 1", "id": 3}
];
I tried
<%-- Set the content type header with the JSP directive --%>
<%@ page contentType="application/json" %>
<%-- Set the content disposition header --%>
<%
// Returns all employees (active and terminated) as json.
response.setContentType("application/json");
response.setHeader("Content-Disposition", "inline");
%>
<%@ page language="java"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="oracle.apps.fnd.common.WebAppsContext"%>
<%@ page import="oracle.apps.fnd.common.WebRequestUtil"%>
<%@ page import="oracle.apps.fnd.common.ResourceStore"%>
<%@ page import="oracle.apps.fnd.common.VersionInfo"%>
[
{"label":"item 1", "value":"item 1", "id": 1},
{"label":"item 2", "value":"item 2", "id": 2},
{"label":"item 3", "value":"item 1", "id": 3}
];
but it does not seem to work, since my jquery autocomplete does not work with it.
Here's part of the autocomplete code:
<html>
<head>
$(function() {
var cust_ac = $("#autocomplete input#cust_input").autocomplete({
source: "xxpay_json_emp.jsp",
change: function (event, ui) { alert(ui.item.id); },
width: 500,
max: 3000,
selectFirst: false,
delay: 250,
minChars: 3,
matchContains: 1,
scroll: false,
scrollHeight: 200,
maxItemsToShow: 20
});
$('#autocomplete').submit(function() {
return false; // Cancel submit button on form.
});
});
function handleKeyPress(e, form)
{
var key = e.keyCode || e.which;
if (key == 13)
{
e.cancelBubble = true;
e.returnValue = false;
}
}
</script>
</head>
<body class='fdlbod'>
<div style='padding-left : 20px'>
<textarea id="holdtext" style="display:none;"></textarea>
<form id="autocomplete" name="autocomplete">
<%
out.println("Customer Name: ");
out.println("<input type='text' value='' name='cust_input' id='cust_input' size='80' onkeypress='handleKeyPress(event,this.form)' />");
%>
</form>
</div>
</body>
</html>