package org.nutz.mvc.view;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.nutz.mvc.Mvcs;

/**
 * 重定向视图
 * <p>
 * 在入口函数上声明：
 * <p>
 * '@Ok("redirect:/pet/list.nut")'
 * <p>
 * 实际上相当于：<br>
 * new ServerRedirectView("/pet/list.nut");
 * 
 * @author zozoh(zozohtnt@gmail.com)
 */
public class ServerRedirectView extends AbstractPathView {

	public ServerRedirectView(String dest) {
		super(dest);
	}

	public void render(HttpServletRequest req, HttpServletResponse resp, Object obj)
			throws Exception {

		String path = evalPath(req, obj);

		// Another site
		if (path.startsWith("http://") || path.startsWith("https://")) {}
		// Absolute path, add the context path for it
		else if (path.length() > 0 && path.charAt(0) == '/') {
			path = req.getContextPath() + path;
		}
		// Relative path, add current URL path for it
		else {
			String myPath = Mvcs.getRequestPath(req);
			int pos = myPath.lastIndexOf('/');
			if (pos > 0)
				path = myPath.substring(0, pos) + "/" + path;
			else
				path = "/" + path;
		}
		resp.sendRedirect(path);
		resp.flushBuffer();
	}

}

@@ -867,258 +867,8 @@
 %0D%0A%09%09
-// Relative path, add current URL path for it%0D%0A%09%09else %7B%0D%0A%09%09%09String myPath = Mvcs.getRequestPath(req);%0D%0A%09%09%09int pos = myPath.lastIndexOf('/');%0D%0A%09%09%09if (pos %3E 0)%0D%0A%09%09%09%09path = myPath.substring(0, pos) + %22/%22 + path;%0D%0A%09%09%09else%0D%0A%09%09%09%09path = %22/%22 + path;%0D%0A%09%09%7D%0D%0A%09%09
 resp
@@ -887,16 +887,40 @@
 t(path);
+ //%E8%BF%99%E4%B8%AA%E5%8E%9F%E7%94%9F%E6%94%AF%E6%8C%81%E7%9B%B8%E5%AF%B9%E8%B7%AF%E5%BE%84%E7%9A%84,%E5%B0%B1%E4%B8%8D%E8%A6%81%E5%86%8D%E5%81%9A%E6%97%A0%E7%94%A8%E5%8A%9F%E4%BA%86
 %0D%0A%09%09resp

修正重定向视图,使用Servlet默认的重定向方法即可,无需自己实现相对路径 fix issue #96