Cheers :)

I actually have an alteration to suggest to the getCurrentUrl() code.
It doesn't take into account when the web code is deployed to a
context path other than the default (no path).

For instance, I deploy on my sandbox under a context path equal to the
branch name (in git) when I am developing. So everything is available
at /foo/someAction instead of /someAction.

The getLastUrl() contains the full path including context path and
when that is coupled with a RedirectResolution it ends up as
/foo/foo/someAction, since RedirectResolution automatically prepends
the context path where necessary.

So to fix this I changed getLastUrl() to strip off the context path :

        String contextPath = this.context.getServletContext().getContextPath();

        if (uri == null) {
            uri = req.getRequestURI();
            if (!"".equals(contextPath) && uri.startsWith(contextPath)) {
                uri = uri.substring(contextPath.length());
            }
            path = req.getPathInfo();
        }

Chris

PS Liking the book so far -  it is easy to understand and follow. I
picked it up as a reference to find things that I can do better in my
code.


On Sat, Jan 5, 2013 at 9:21 PM, Freddy Daoud <xf2...@fastmail.fm> wrote:
> Hi Chris,
>
> There sure is. You can download all the code here:
> http://pragprog.com/titles/fdstr/code
>
> Hope that helps.
> I hope you enjoy the book!
>
> Cheers,
> Freddy
>
> On Sat, Jan 5, 2013, at 09:12 PM, Chris Cheshire wrote:
>> Freddy,
>>
>> Is there an accompanying download for the book? I bought the book this
>> week, and got stuck on this bit of the redirect after login until I
>> found this thread.
>>
>> Cheers,
>>
>> Chris
>>
>> On Sun, Oct 11, 2009 at 12:11 AM, Freddy Daoud <xf2...@fastmail.fm>
>> wrote:
>> > Hi Rusty,
>> >
>> >> How do I get the url for the current page?  I need it for a redirect back
>> >> to the current page after the user logs in.
>> >
>> > Here's how I do it in the Stripes book:
>> >
>> >     public String getLastUrl() {
>> >
>>
>>
>> > Lordy, that's a lot of code!
>>
>> Haha - yep, that's why it wasn't printed in the
>> Stripes book ;)
>>

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to