Set Content-Type to application/json in jsp file

前端 未结 3 436
醉梦人生
醉梦人生 2020-12-14 06:20

I am created some jsp file that returns as a response some json string. But I see that the Content-Type is set to txt automatically

My jsp code looks like



        
3条回答
  •  隐瞒了意图╮
    2020-12-14 06:31

    You can do via Page directive.

    For example:

    <%@ page language="java" contentType="application/json; charset=UTF-8"
        pageEncoding="UTF-8"%>
    
    • contentType="mimeType [ ;charset=characterSet ]" | "text/html;charset=ISO-8859-1"

    The MIME type and character encoding the JSP file uses for the response it sends to the client. You can use any MIME type or character set that are valid for the JSP container. The default MIME type is text/html, and the default character set is ISO-8859-1.

提交回复
热议问题