相关疑难解决方法(0)

如何简单地从JSP返回JSON

任何人都可以给我一个例子,说明如何从没有任何外部库的jsp返回以下json(除了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}
];
Run Code Online (Sandbox Code Playgroud)

我试过了

<%-- 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"%> …
Run Code Online (Sandbox Code Playgroud)

json jsp

13
推荐指数
3
解决办法
7万
查看次数

标签 统计

json ×1

jsp ×1