我正在尝试在某些 JavaScript 中访问 Spring Source Security 用户变量 ${username} 并且它一直以空字符串的形式返回。在上一页中,我仅使用 ${username} 显示用户名。据我所知,我需要做的就是在 javascript 中得到它:
<c:out value="${username}"/>
但是在下面的代码中,生成的 HTML 总是有一个空字符串。我错过了什么?
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Admin Page</title>
<style type="text/css">
.wideCols .field-radio { width: 5%; }
.wideCols .field-username { width: 15%; }
.wideCols .field-firstName { width: 15%; }
.wideCols .field-lastName { width: 20%; }
.wideCols .field-email { width: 40%; }
.wideCols .field-enabled { width: 5%; }
</style>
</head>
<body>
<h1>Users</h1>
<spring:url value="/admin/addUser" var="accountUrl" />
<a href="${accountUrl}">Add User</a>
<div id="result1"></div>
<div id="grid" class="wideCols"></div>
<!-- <button type="button" id="saveNode"></button> -->
<script type="text/javascript">
require([ "dojo/store/JsonRest",
"dojo/_base/declare",
"dgrid/OnDemandGrid",
"dgrid/Selection",
"dgrid/editor",
"dgrid/selector",
"dojo/domReady!"
], function(JsonRest, declare, OnDemandGrid, Selection, editor, selector) {
var userAccountStore = new JsonRest({
idProperty : "userAccountId",
target : "<c:url value="/userMgr/" />"
});
window.grid = new (declare([OnDemandGrid, Selection]))({
store : userAccountStore,
columns: [ selector({ label: 'radio'}, "radio"),
{ label: "Username", field: "username"},
{ label: "First Name", field: "firstName"},
{ label: "Last Name", field: "lastName"},
{ label: "Email", field: "email"},
editor({ label: "Enabled", field: "enabled", autoSave: "true", canEdit: function(object){
return object.username != "<c:out value="${username}"/>";
}, }, "checkbox")],
}, "grid");
});
</script>
</body>
</html>