1

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!

3
  • possible duplicate of stackoverflow.com/questions/10595775/… Commented Oct 25, 2016 at 19:28
  • @Matt1776 tried the solution in that one already and no luck :/ Commented Oct 25, 2016 at 20:24
  • Can you show how you used that solution ? Use a REST Client to test your URL (I like Postman on Chrome for that). Commented Oct 26, 2016 at 14:37

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

basically I was returning a JSON Object rather than a String, the browser and obviously my Spring didnt know what to do with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.