代码之家  ›  专栏  ›  技术社区  ›  Jin Lee

我不明白为什么会出现JSP语法错误(多注释)

  •  0
  • Jin Lee  · 技术社区  · 6 年前

    (我从谷歌搜索得到了源代码。我自己在打一些代码来学习。我检查了三遍,键入的内容与源代码相同。我甚至复制和粘贴了它,但仍然得到相同的错误。)

    <% UserBean currentUser = (UserBean (session.getAttribute("currentSessionUser"));%>
    

    在JSP文件中,我得到了一个语法错误。我附上了详细的截图。我在前面创建了Userbean.java和setAttribute“currentSessionUser”。

    enter image description here

    下面是该JSP页面的完整代码(html标记没有出现在代码中,所以我添加了一个屏幕截图。 (小问题) <&燃气轮机;在这里似乎不起作用。)

    enter image description here

    谁能猜出我为什么会有语法错误吗?

    我试过了
    <% UserBean currentUser = (UserBean (session.getAttribute("currentSessionUser")));%> //three closing brackets

    <% UserBean currentUser = UserBean (session.getAttribute("currentSessionUser"));%> //removing the bracket in front of UserBean

    1 回复  |  直到 6 年前
        1
  •  2
  •   Scary Wombat    6 年前
     <% UserBean currentUser = (UserBean (session.getAttribute("currentSessionUser"));%> 
    

    只需计算左括号和右括号的数目。 但你看起来想做的是 cast

    所以

    UserBean currentUser = (UserBean) (session.getAttribute("currentSessionUser"));
    

    顺便说一句,在JSP中使用EL可能更好,而不是java