Shrio登入失敗重定向到登入頁面顯示錯誤資訊

2021-09-25 02:56:41 字數 1154 閱讀 2200

controller 的shiro登入方法如下

public string login(redirectattributes redirectattributes, @valid userbean userbean, bindingresult bindingresult) catch (unknownaccountexception e) catch (lockedaccountexception e) catch (authenticationexception e) catch (exception e)

subject.getsession().setattribute("message", "密碼錯誤");

return "redirect:/againlogin.do";

} else );

redirectattributes.addflashattribute("message", buffer.tostring());

return "redirect:/againlogin.do";

}}

redirectattributes 是spring mvc 3.1版本之後出來的乙個功能,專門用於重定向之後還能帶引數跳轉的的工具類

redirectattributes 的 addattribute("param", value)  是在url後拼接引數

redirectattributes 的 addflashattribute("param", value)  重新向帶參,而且能隱藏引數,其原理就是放到session中,session在跳到頁面後馬上移除物件。所以你重新整理一下後這個值就會丟掉

其中 redirect:/againlogin.do  這個返回結果是跳向另乙個controller方法  againlogin.do 

如下

@controller

public class indexcontroller

}

頁面顯示儲存得message資訊如下

index.html 使用 thymeleaf 檢視渲染 

效果如下 輸入錯誤的密碼如下

重定向到登入頁面

我現在想學asp.net,我看別人的 發現下面一句 formsauthentication.redirectfromloginpage userid,false 能重定向至另一頁面,但這裡並沒有指定要轉向那個頁面啊,原來在web.config有配置啊 code code 呵呵,這個東西很爽的,當用了...

實踐筆記 Vue登入重定向失敗

使用動態路由下,進行非同步請求的同時,不能進行重定向。1.等待非同步請求完成後再進行路由重定向 載入選單 util.initrouter this then res 2.改寫initrouter 方法一 將非同步請求方法寫成promise,之後使用then鏈式呼叫 util.initrouter f...

django 中登入之後next重定向到之前的網頁

查了很多網頁,好像也沒有想要的結果,後來突然想到把 next 引數也post到後端,然後實現跳轉即可 前端type hidden value name next 後端 if request.post.get next return redirect request.post.get next 當然,...