¿Alguien me puede dar un ejemplo de cómo devolver el siguiente json simplemente desde un jsp sin ninguna biblioteca externa (excepto las que vienen de manera estándar con Oracle Java)?Cómo devolver JSON desde un JSP
[
{"label":"item 1", "value":"item 1", "id": 1},
{"label":"item 2", "value":"item 2", "id": 2},
{"label":"item 3", "value":"item 1", "id": 3}
];
me trataron
<%-- 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}
];
pero no parece funcionar, ya que mi jQuery autocompletado no funciona con ella.
Aquí es parte del código de autocompletar:
<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>
¿Y qué sale? La condición "JQuery no funciona" puede tener muchas causas. –
¿Por qué no hay bibliotecas externas? Una biblioteca JSON es muy fácil de usar y la única forma real de hacerlo. 'oracle.apps.fnd' tampoco viene con Java, por cierto. – Thilo
No soy lo suficientemente inteligente como para descubrir cómo agregar bibliotecas externas a la instalación de Oracle java. – Superdooperhero