Home > other >  How to generate json from jsp? Not HTML
How to generate json from jsp? Not HTML

Time:08-05

I am trying to use jsp to generate json. The problem is, there is generated a HTML which contains my json. The point not to generate html.

enter image description here
Java7, JBoss4 and jsf probably 2.5.
Thanks

CodePudding user response:

The problem is not on the JSP side. Your JSP returns a valid Json, and the browser (Chrome) adds the HTML.

For example, with a JSP containing this source:

<%@ page contentType = "application/json" %>
{"test": {"value": "1", "value2" : "2", "value3" :  "3"}}

Google will display: Json displayed with Chrome

While Firefox will display: enter image description here

CodePudding user response:

Maybe you should set the content type on your JSP:

<%@ page contentType = "application/json" %> 

but the HTML is produced by your code so you should remove that part.

  • Related