1

Noir provide (response/redirect "url") for client-side 302 redirect. But how to redirect within the web server its-self? For example, writing a login page, if logging failed, how to redirect to the error page with a message?

(defpage [:post "/error"] {:keys [msg]}
  (layout [:h3 "ERROR:"] [:p msg]))

(defpage [:post "/do-login"] {:keys [user pass]}
  (if (match user pass)
    (login-ok)
    (redirect-to-error-page but how to carry msg)))
qiuxiafei
  • 5,827
  • 5
  • 30
  • 43

1 Answers1

0

You can send a new page using 'render', see http://webnoir.org/tutorials/forms for an example much like yours:

(render "/errorpage" msgid)

The message will arrive as an id, e. g. "/errorpage/1001", which you can pick up with the :id notation, see the answer by @dAni in Noir render function causes NullPointerException for how to use that. You can even name your pages!

Community
  • 1
  • 1
0dB
  • 675
  • 5
  • 13
  • i’ve tried render, but it's just show another page with the old page's url. Is redirecting in server possible? – qiuxiafei Oct 31 '12 at 03:35
  • I see. No, I do not know that. – 0dB Oct 31 '12 at 04:13
  • 1
    @qiuxiafei: If you want the URL also be updated in browser then you need to do client side redirection. Server side redirection has no way to tell the browser about new URL as it is just a response to the login page request – Ankur Oct 31 '12 at 04:16
  • @Ankur what about http://en.wikipedia.org/wiki/URL_redirection#HTTP_status_codes_3xx? – Cubic Oct 31 '12 at 10:04
  • @Cubic: This is what `client side redirection` is i.e the response goes back to browser and then browser automatically redirects to the URL mentioned in the response. Server side redirection means in the same single request response cycle you return content of other handler. Ex: Server.redirect in ASP.NET – Ankur Oct 31 '12 at 10:25
  • @Ankur, care to turn your comment into an answer? – 0dB Nov 03 '12 at 03:24