Re: [問題] 為何jsp的sendRedirect 一旦沒有成功될…
是程序的問題
不管你寫asp, jsp, php
要redirect都要在任何html code之前出現
因為redirect是運用http header中的location欄位轉換網頁的
瀏覽器都在要求(request)網頁下載時, 第一個會接收的就是http header
再來是接收html content
所以你不能在html content中指定http header
你可以把redirect往前移到何任html code之前
或改用forward?
http://www.javapractices.com/Topic181.cjp
※ 引述《Oreilly (Vendetta 我心無所懼)》之銘言:
: 如果這支JSP沒有成功sendRedirect(url)
: 它就死掉了
: 接下來其他人也都連不到了
: 為何會如此呢? 是我哪邊沒處理嗎 ?? > <
: <%@page contentType="text/html"%>
: <%@page pageEncoding="UTF-8"%>
: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
: "" rel="nofollow">http://www.w3.org/TR/html4/loose.dtd">
: <html>
: <head>
: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
: <title></title>
: </head>
: <body>
: <h1>Spring</h1>
: <%
: String id = request.getParameter("id");
: String url="http://xxx/yyy/zzz.jsp?id=" + id ;
: response.sendRedirect(url);
: %>
: </body>
: </html>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.26.34.214
討論串 (同標題文章)
java 近期熱門文章
PTT數位生活區 即時熱門文章