当前位置: 代码迷 >> Java Web开发 >> CAS 返回多个中文参数 总乱码,郁闷中
  详细解决方案

CAS 返回多个中文参数 总乱码,郁闷中

热度:1094   发布时间:2013-02-25 21:16:19.0
CAS 返回多个中文参数 总乱码,郁闷中,请教各位
小弟是新手,在调试CAS传递多个中文参数时出现了 乱码,并且修改WEB-INF/view/jsp/protocol/2.0/casServiceValidationSuccess.jsp该文件,顶部加上一行<%@page pageEncoding="UTF-8"%>,后返回如下错误,我的服务器用的是 cas-3.3.5 客户端用的是cas-client -3.0.10 ,打开WEB-INF/view/jsp/protocol/2.0/casServiceValidationSuccess.jsp文件删除“<%@page pageEncoding="UTF-8"%>”恢复正常,能够拿到数据了,但还是乱码。

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: org.jasig.cas.client.validation.TicketValidationException: No principal was found in the response from the CAS server.
root cause 

org.jasig.cas.client.validation.TicketValidationException: No principal was found in the response from the CAS server.
note The full stack traces of the exception and its root causes are available in the GlassFish v3 logs.


------解决方案--------------------------------------------------------
传递一个中文参数行不?
以前能传递不?
不如先uriencode成英文字符串
传递过来了再解码
------解决方案--------------------------------------------------------
cas2.0协议的验证结果页面是通过目录:cas/WEB-INF/view/jsp/protocol/2.0/ 下定义的jsp(jstlview)模板页面来定义的。
casProxySuccessView.jsp:对应验证成功的页面(这个页面还包含用户登录的帐户名)。
casServiceValidationFailure.jsp:对应验证失败页面。
乱码解决办法:
在casProxySuccessView.jsp和casServiceValidationFailure.jsp页面代码的最前面加上:<%@page pageEncoding="pagecharset"%>
其中pagecharset为页面编码,可以换为你想要的编码(GBK或是gb2312或是utf-8)。

如果还不行,试试下面两步:

1)修改CAS登陆验证页面的编码,如果你没换过这个主题的话,默认的是修改WEB-INF\view\jsp\default\ui\casLoginView.jsp文件,在最上面加上<%@ page pageEncoding="gb2312"%>。这里要特别注意一下,这个页面的编码要和上面XML文件里写的编码一致。

2)修改验证成功后做跳转的页面。也就是WEB-INF\ view\ jsp\ protocol\ 2.0\ casServiceValidationSuccess.jsp文件,在最上面加上<%@ page pageEncoding="UTF-8"%>。这里特别注意的是这个页面的编码要和你跳转过去的那个页面的编码一致,换句话说,客户端的验证页面的编码要和这个地方的一致,不一致的话,要转换一下。


------解决方案--------------------------------------------------------
探讨
No principal was found in the response from the CAS server.

------解决方案--------------------------------------------------------
请这样修改如XML/HTML代码: 
<c:if test="${fn:length(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.attributes) > 0}"> 
<cas:attributes> 
<c:forEach var="attr" items="${assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.attributes}">
<c:set var="key" value="${fn:escapeXml(attr.key)}" scope="request"> 
<c:set var="value" value="${fn:escapeXml(attr.value)}" scope="request"> 
<cas:${key}><%=URLEncoder.encode((String)request.getattribute("value"),"UTF-8")%></cas:${key}> 
</c:forEach> 
</cas:attributes> 
</c:if> 

我已经帮你调试通过。然后又到客户端用URLDecoder.decode()解码.--结贴吧。呵呵
  相关解决方案