我正在尝试获取用户可以在spring mvc web app中的CAS登录页面选择的所选语言。即使它能够通过会话获得用户名,所选择的语言也不能通过会话,因为它最终变为'null'。
到目前为止,这是尝试过的内容。为了让用户进入jsp页面,使用了以下内容并且工作正常。
<%
AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal();
session.setAttribute("casPrincipal", principal);
session.setAttribute("username", request.getRemoteUser());
Map attributes = principal.getAttributes();
Iterator attributeNames = attributes.keySet().iterator();
for (; attributeNames.hasNext();) {
String attributeName = (String) attributeNames.next();
Object attributeValue = attributes.get(attributeName);
session.setAttribute(attributeName, attributeValue);
}
String redirectURL = request.getContextPath() + "/webapp.html";
response.sendRedirect(redirectURL);
%>
<div class="row">
<b><a id="user" href="#" >Welcome <%= session.getAttribute("username")%></a></b>
</div>
要获取所选语言,请尝试以下操作。在自定义CAS登录页面中,
<%= request.getParameter("locale")%>
<%
String w1= request.getParameter("locale");
session.setAttribute("ur", w1);
%>
为获取该语言,已尝试在主页中跟随,但它显示为“null”。那可能是什么原因呢?怎么能解决这个问题?
<%=session.getAttribute("ur")%>