tags:

views:

33

answers:

1

Hi, everyone,

I want to ask some questions about the JSP and JSON file. I have a JSON format file which put in the tomcat server. And I use the JSP to write the web application. When the user types the URL and open the JSP page, the JSP page will get the file in the tomcat server (e.g. it can assume the file in the "c://location").

After received the file, the content will display in the JSP page.

However, I don't know how to make the JSP page to get the file in the tomcat server when the user call the URL. Can anyone help me? Thank you.

+2  A: 
  • load the file into a stream - `InputStream is = new FileInputStream("/path/to/file.json");
  • write it to the output stream. For example with commons-io - IOUtils.copy(is, response.getOutputStream())
  • set the content-type - response.setContentType("application/json");
Bozho
@Bozho, thank you very much.
Questions