Reputation: 21
So I'm working on an old application and I'm forced to use JSP at the moment, which I'm extremely unfamiliar with (and unfamiliar with most aspects of web development tbh).
I'm generating a JSON Array using JSONSimple in a Java class method, and then invoking that method from a JSP on a GET request to get the JSON. Sounds simple enough.
I was able to get my JSON when accessing the URL in my browser. Now I'm trying to access my JSP page from another application, and that's where I'm having difficulty. The content type of my "JSON" was text/html, and not JSON, so I tried setting the content type to JSON in my JSP, and now nothing is showing up in browser, and my Spring application is giving me this error when I try to get JSON from the URL: Could not read document: No content to map due to end-of-input at....
Here's my JSP:
<%@ page import="com.company.Someclass" %>
<% if(request.getMethod().equals("GET")){
response.setContentType("application/json");
Someclass.getJSONArray();
}
else if(request.getMethod().equals("POST")){
//todo
}
%>
Any help would be greatly appreciated as I'm pretty lost at the moment. Thanks!
Upvotes: 1
Views: 662
Reputation: 21
Fixed this myself. I'm able to get JSON in the browser, but having trouble reading it in my Spring application. but thats another battle. Here's my solution:
<%@ page import="com.company.Someclass" %>
<% String ret = "";
if(request.getMethod().equals("GET")){
response.setContentType("application/json");
Someclass.getJSONArray().toJSONString();
}
else if(request.getMethod().equals("POST")){
//todo
}
%>
<%= ret %>
the toJSONString() is a method of json-simple's JSONArray class
Upvotes: 1