日期:2014-05-17  浏览次数:20728 次

登录或者注册之后如何重定向到刚才访问的页面?
动态redirect啊,要怎么做呢,servlet没学好,思路应该是要获取提交表单时的url,自己new一个actionforward然后setpath转发,问题是如何获取呢

------解决方案--------------------
如果请求的URL为:http://localhost:8080/webapp/login

1.request.getURI( )返回HTTP请求行中请求URI的部分。上例中该方法将返回/webapp/login。

2.request.getContextPath( )返回web应用程序的路径,上例中该方法将返回/webapp。

3.request.getServletPath( ) 返回Servlet的路径。上例中该方法将返回/login。

4.request.getURL( )返回请求的URL,上例中即为http://localhost:8080/webapp/login