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

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:新增資料到Header裡面去 [Re:mousetail]
mousetail





發文: 142
積分: 1
於 2004-09-08 08:57 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
frank 大大 您好!

所以我應該在test.jsp先response header, 然後在下一頁去request header嗎?程式碼如下:
test.jsp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<%@ page contentType="text/html;charset=Big5" language="java"  import="java.lang.*,java.util.*,java.net.*,java.io.*,javax.servlet.http.*"%>
<%
  URL u = new URL("http://localhost:8080/new_trade_local_utf8/test1.jsp");
  URLConnection uc = u.openConnection(); 
  uc.setRequestProperty("ordChannel","Js");
 
  response.addHeader("ordChannel", "Js");  // for HTTP 1.1
 
    Enumeration e;
    String Lpid ="",Laccounts="",Lroles="";
    e = request.getHeaderNames();
    while(e.hasMoreElements()){
      String key = (String)e.nextElement();
      Lpid = request.getHeader(key);
      out.println("key="+key+" ;     value="+Lpid+"<br>");
    }
    
 
%>
<a href="test1.jsp">test1.jsp</a>


test1.jsp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<%@ page contentType="text/html;charset=Big5" language="java"  import="java.lang.*,java.util.*,java.net.*,java.io.*,javax.servlet.http.*"%>
<%
  String ordChannel = request.getHeader("ordChannel");
  
  out.print("ordChannel:"+ordChannel+"<br>");
  
  
 
    Enumeration e;
    String Lpid ="",Laccounts="",Lroles="";
    e = request.getHeaderNames();
    while(e.hasMoreElements()){
      String key = (String)e.nextElement();
      Lpid = request.getHeader(key);
      out.println("key="+key+" ;     value="+Lpid+"<br>");
    }
    
 
%>


結果如下:
1
2
3
4
5
6
7
8
9
ordChannel:null
key=Accept ; value=image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
key=Referer ; value=http://localhost:8080/new_trade_local_utf8/test.jsp
key=Accept-Language ; value=zh-tw
key=Accept-Encoding ; value=gzip, deflate
key=User-Agent ; value=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
key=Host ; value=localhost:8080
key=Connection ; value=Keep-Alive
key=Cookie ; value=JSESSIONID=a3-bPXNrOTcc


一樣還是得到 null ,不知道我這樣做是否是正確的呢

謝謝您!!!


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
3700 新增資料到Header裡面去 mousetail 1263 2004-09-07 19:12
3992 Re:新增資料到Header裡面去 frank 1078 2004-09-07 21:52
3176 Re:新增資料到Header裡面去 mousetail 2473 2004-09-08 08:57
3056 Re:新增資料到Header裡面去 frank 628 2004-09-08 10:20
» JWorld@TW »  Servlet/JSP 討論區

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