【问题标题】:Accessing JSONObject properties in JSP using EL expression使用 EL 表达式访问 JSP 中的 JSONObject 属性
【发布时间】:2020-02-13 06:45:59
【问题描述】:

我有一个 servlet,可以将字符串转换为 JSONObject,如下所示:

JSONObject myObject = new JSONObject("{'someKey':'someValue'}"); 
//sending it to the JSP with RequestDispatcher
request.setAttribute("jsonObject", myObject)
requestDispatcher.forward(request, response);

现在在 JSP 中,我尝试使用 EL 表达式 ${jsonObject.someKey} 访问它,但出现以下错误:

javax.el.PropertyNotFoundException: The class 'org.json.JSONObject' does not have the property 'someKey'.

【问题讨论】:

    标签: java json jsp el


    【解决方案1】:

    希望对你有帮助。

    ${jsonObject.get("someKey")}
    

    【讨论】:

    • 2 年后它有所帮助:)
    猜你喜欢
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    相关资源
    最近更新 更多