JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Certification  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 有關session的問題
yanyonyuen





發文: 39
積分: 0
於 2004-10-23 10:03 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
有兩個servlet如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//class definition for servlet A1
  public class A1 extends HttpServlet{
     public void doPost(HttpServletRequest req,HttpServletResponse res){
         req.getSessin().setAttribute("ID","12345");
     }
     public void doGet(HttpServletRequest req,HttpServletResponse res){
         req.getSessin().invalidate();
     }
  }
 
//class definition for servlet B1
  public class B1 extends HttpServlet{
     public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException{
         String id = (String)req.getSession().getAttribute("ID");
         res.getWriter().println(id);
     }
  }


Assume servlets A1 and B1 are in the same Web application.Give that the HTTP requests are fully processed in this order.
1)POST method to A1
2)GET method to A1
3)POST method to B1
What is the result?
A.Compilation fails.
B.An exception is thrown at line 4 in servlet B1
C."null" is returned in the generated servlet response
D."12345" is returned in the generated servlet response

我是選d,正確答案是c
請問是不是因為執行了req.getSessin().invalidate();之後,session就會不存在了,而B1的String id = (String)req.getSession().getAttribute("ID");是不是再一次的重新產生一個session


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
2514 有關session的問題 yanyonyuen 1201 2004-10-23 10:03
2193 Re:有關session的問題 FireFox 182 2004-10-23 17:46
1992 Re:有關session的問題 yanyonyuen 249 2004-10-25 11:20
2382 Re:有關session的問題 FireFox 179 2004-10-25 15:26
2164 Re:有關session的問題 FireFox 62 2004-10-25 15:27
1968 Re:有關session的問題 yanyonyuen 14 2004-10-25 18:35
» JWorld@TW »  Java Certification

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8