response對象中的Redirect方法的使用

Redirect方法
  該方法使瀏覽器可以重新定位到另一個URL上,這樣,當客戶發出Web請求時,客戶端的瀏覽器類型已經確定,客戶被重新定位到相應的頁面。如:
<html>
<head>
<title>Redirect示例</title>
</head>
<body>
<form aciton="formjump.asp" method="post">
  <select name="wheretogo">
    <option selected value="fun">Fun</option>
    <option value="news">News</option>
    <option value="sample">Sample</option>
  </select>
<input type=submit name="jump" value="Jump">
</form>
</body>
</html>
  以上是提交的表單,下面是處理表單的文件formjump.asp:
<%response.buff=true%>
<html>
<head>
<title>Redirect示例</title>
</head>
<body>
<%
thisurl="
http://jefenet.yesky.net"
where=Request.form("wheretogo")
Select Case where
  case "fun"
     response.redirect thisurl & "/fun/default.asp"
  case "news"
     response.redirect thisurl & "/news/default.asp"
  case "sample"
     response.redirect thisurl & "/sample/default.asp"
End Select
%>
</body>
<html>
  這個例子當用戶選擇了以後,按"Jump"按鈕提交表單,服務器接到申請後調用formjump.asp判斷後定位到相應的URL。不過這裏有一點要注意,HTTP標題已經寫入到客戶瀏覽器,任何HTTP標題的修改必須在寫入頁內容之前,遇到這種問題時,可以如下做:
在文件的開始<@ Language=..>後寫:   
   Response.Buffer=True
在結尾定:
   Response.Flush
  這裏Flush是Response的一個方法,它必須是Buffer屬性設置爲True時才能使用,否則會產生一個運行模式錯誤。另外一個Clear方法也是用於清除被緩存的頁面,同樣要Buffer屬性設置爲True時才能使用。
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章