我想在javascript中检索请求范围属性,如下所示。我怎样才能做到这一点?
function caseChanges(req) {
var innervalue= "${dashboardTicketSummary}"
alert("nand you are 1234");
alert(innervalue);
}
我想在javascript中检索请求范围属性,如下所示。我怎样才能做到这一点?
function caseChanges(req) {
var innervalue= "${dashboardTicketSummary}"
alert("nand you are 1234");
alert(innervalue);
}
假设 javascript 被内联包含在 jsp 页面上——你在正确的轨道上,你只需要确保在 HttpServletRequest 对象上设置了属性(通常由你的控制器类),即:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res)
{
DashboardTicketSummary dts = ...; // code to obtain ticket summary here
req.setAttribute("dashboardTicketSummary", dts);
// code to dispatch to your jsp page here
}
当然还有很多其他更复杂的方法——尤其是你使用流行的 MVC 框架,比如 Spring
设置值以请求属性并将这段代码写入jsp页面上的脚本标记(如index.jsp):
<script>
function caseChanges(req){
var innervalue= "${dashboardTicketSummary}"
alert("nand you are 1234");
alert(innervalue);
}
</script>
为了更好的可维护性,您可以将所有属性收集到 jsp 上的全局对象中,并在其他 js 文件中引用它:
索引.jsp
<script>
var REQUEST_ATTRS = {
dashboardTicketSummary : '${dashboardTicketSummary}',
otherAttributes :'${otherAttributes}'
};
</script>
其他.js
function caseChanges(req){
var innervalue= REQUEST_ATTRS.dashboardTicketSummary ;
alert("nand you are 1234");
alert(innervalue);
}