package idc.json.command;

import idc.model.IdcCmd;

import java.io.IOException;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

public class IdcSetTokenJSONCmd implements IdcCmd
{
	//토큰 셋팅
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
	{
		JSONObject obj=new JSONObject();
		Random r = new Random();
		int rand = r.nextInt(1000)+1;
		
		request.getSession().setAttribute("token", rand);
		
		obj.put("a", rand);
		
		response.setCharacterEncoding("utf-8");
		response.setContentType("application/json");
		try
		{
//			System.out.println("토큰값 : " + obj.toString());
			response.getWriter().write(obj.toString());
		} 
		catch (IOException e)
		{
			System.out.println("IdcSetTokenJSONCmd - SendError");
			e.printStackTrace();
		}
	}
}
