画面遷移
JSPの画面遷移
共通の画面遷移
ASP.NETの画面遷移
Redirect VS Transfer(他サイト参照)
遷移方法
HTMLの<a>タグ
JavaScript
サンプル
<a href=”test.aspx”>別ページへ</a>
window.location.href = 'test.html';
setTimeout("javascript:location.href='test.html'", 3000);
★PRG(Post-Redirect-Get)パターン
フォームの送信後に表示する画面でF5キーやブラウザの更新ボタンをクリックすることで
内容の二重送信を防ぐため
SAStruts例
/** 入力画面 */
@Execute(validator=false)
public String input() {
return "input.jsp";
}
/** 登録画面 */
@Execute(validator=true, input="input.jsp")
public String register() {
...
return "complete?redirect=true";
}
/** 完了画面 */
@Execute(validator=false)
public String complete() {
return "complete.jsp";
}
★Redirectのいろいろ
HTML
<meta http-equiv="refresh" content="0; URL='http://new-website.com'" />
JavaScript
window.location = "http://new-website.com";
Apache (mod_rewrite必須)
Redirect 301 / http://www.new-website.com
RedirectMatch 301 /blog (.*) http://www.new-website.com$1
Redirect 301 /page.html http://www.old-website/new-page.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* 404.html [L]
Nginx
server {
listen 80;
server_name old-website.com;
return 301 $scheme://new-website.com$request_uri; }
Lighttpd
server.modules = (
"mod_redirect"
)
$HTTP["host"] =~ "^(www\.)?old-website.com$" {
url.redirect = (
"^/(.*)$" => "http://www.new-website.com/$1",
)
}
PHP
header('Location: http://www.new-website.com/', true, 301);
exit();
Node.js
var http = require ("http");
var url = require ("url");
http.createServer (function (req, res) {
var pathname = url.parse (req.url) .pathname;
res.writeHead (301,{Location: 'http://new-website.com/' + pathname});
res.end ();
}) .listen (8888);