2008. 9. 8. 14:57

session.setAttribute 에서 주의할 점

protected void doPost(HttpServletRequest req, HttpServletResponse res)
                                        throws ServletException, IOException {
                                         
        HttpSession session = req.getSession(true);
        int total = 0;
        int robot1 = 1;
        int lego1 = 1;
        total = robot1+lego1;
       
        if(session.isNew()){
         session.setAttribute("imdi", total);
         session.setAttribute("robot", new int[] {0});
         session.setAttribute("lego", new int[]{0});
        }            

--> int type 을 그대로 입력하면 에러!

 

   HttpSession session = req.getSession(true);
        int total = 0;
        int robot1 = 1;
        int lego1 = 1;
        total = robot1+lego1;
       
        if(session.isNew()){
         Integer itotal = new Integer(total);
         // 형변환이 반드시 이루어져야함
         // Session 는 object 형만 가능하다.
         session.setAttribute("imdi", itotal);
         session.setAttribute("robot", new int[] {0});
         session.setAttribute("lego", new int[]{0});
        }    

'My work space > JSP/Servlet' 카테고리의 다른 글

session사용  (0) 2008.09.08
세션설정,세션에서 값 가져오기  (0) 2008.09.08
request 객체  (0) 2008.09.08
request.getAttribute  (0) 2008.09.08
jsp/Servlet 기본2  (0) 2008.09.08