如何使用JSTL sql:query访问重复的列名?

Chl*_*loe 4 java sql jsp jstl

出于某种原因,这个

    <sql:query dataSource="${ds}" sql="select user.id, user.name as userName, city, state, country, country.name as countryName, latitude, longitude, ip, last_visit from user, country where user.country = country.id order by last_visit desc limit 100" var="result"/>
    <c:forEach var="col" items="${result.columnNames}">
        ${col}, 
    </c:forEach>
Run Code Online (Sandbox Code Playgroud)

产生

id, name, city, state, country, name, latitude, longitude, ip, last_visit,
Run Code Online (Sandbox Code Playgroud)

哪个错了.我专门重命名了查询中的列.我不知道它是如何找到原始字段名称的.那么如何访问user.name的值呢?${row.userName}不起作用.

我正在使用JSTL jstl-1.2.2.

sge*_*des 6

不确定这是否有帮助,但我已经读过使用别名并不总是能正常工作.我见过一个可能的替代方案:

 <sql:query dataSource="${ds}" sql="select user.id, concat(user.name,'') as userName, city, state, country, concat(country.name,'') as countryName, latitude, longitude, ip, last_visit from user, country where user.country = country.id order by last_visit desc limit 100" var="result"/>
    <c:forEach var="col" items="${result.columnNames}">
        ${col}, 
    </c:forEach>
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.祝好运.