我用的是informix数据库。因为它有很多编码不支持,所以,查出来的数据肯定是乱码的。
但是如果仅仅是用struts2的s标签和jstl标签和el表达式。我是可以处理乱码的。
我封装了一个类,专门进行编码转换的。比如:
<%= Unicode2GB.UnicodeToGB((String)request.getAttribute("code"))%>
这句话就把字符串专程中文了。
request.getAttribute("code")则是相当于${code}现在我要做一个树形菜单。用的是struts2的标签做的,代码如下:<sx:tree label="险种大类" templateCssPath="/struts/tree.css"
                showRootGrid="true" showGrid="true" treeSelectedTopic="treeSelected">
                <s:iterator value="codelist">
                 <sx:treenode label="%{code}%{name}">
                
                 </sx:treenode>
                </s:iterator>
                
            </sx:tree>
现在问题来了,这是从数据库里查询出来的。%{name}是中文,所以是乱码。但是我现在用<%= Unicode2GB.UnicodeToGB((String)request.getAttribute("name"))%>报错了。
我想原因就是%号的问题。
因为之前是el表达式${},但现在是%{},请教各位大虾,我该怎么把%{name}值得到再转化成中文呢。
或者有没有其他的方法来实现这个动态的树形菜单呢?期待如果方便,请联系我:[email protected]谢谢!