

import javax.servlet.jsp.PageContext;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
/**
 * <p>Titre : </p>
 *
 * <p>Description : </p>
 *
 * <p>Copyright : Copyright (c) 2011</p>
 *
 * <p>Société : </p>
 *
 * @author non attribuable
 * @version 1.0
 */
public class jsonP
{
    public jsonP()
    {
    }

    public static void setJSONContent (Object[] tabParam)
    {
        ServletOutputStream out = null;
        // Recuperation du page context (mot cle Adelia *PAGE_CONTEXTE, 1er parametre de la methode)
        PageContext pc = (PageContext) tabParam[0];
        // Recuperation du 2eme parametre (type Adelia ALPHA)
        String json = (String) tabParam[1];
        // Transformation de la chaine en tableau de bytes
        // Attention : encodage en UTF-8
        byte[] tab = json.getBytes();
        ServletResponse res = pc.getResponse();
        try
        {
            out = res.getOutputStream();
        }
        catch (IOException ex)
        {
        }
        // Fixer le type mime JSON
        res.setContentType("application/json; charset=UTF-8");
        // Fixer la taille de la reponse
        res.setContentLength(tab.length);
        try
        {
            out.write(tab);
            out.flush();
            out.close();
        }
        catch (IOException ex1)
        {
        }
    }
}
