0

(I got the source code from Google search. I was typing some code myself to learn. I triple checked and my typing is the same as the source. I even copied and pasted it, but still got the same error.)

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

In the JSP file, I'm getting a syntax error here. I attached a screenshot of its details. I made Userbean.java and setAttribute "currentSessionUser" earlier.

enter image description here

Here is the full code of that JSP page. (html tags doesn't appear in the code, so I added a screenshot. (Minor question) Is there a way to show html tags here? < > doesn't seem to work here.)

enter image description here

Can anyone guess why I'm getting a syntax error?

I've tried
<% UserBean currentUser = (UserBean (session.getAttribute("currentSessionUser")));%> //three closing brackets

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

  • 1
    <% UserBean currentUser = (UserBean (session.getAttribute("currentSessionUser")));%> //three closing brackets. This looks good. Have you tried clean building the application? – RiyaGeorge Mar 12 at 1:14
  • @RiyaGeorge I think the writer of this code forgot to close ) in UserBean casting. thank you for your comment~ – Jin Lee Mar 12 at 1:23
2
 <% UserBean currentUser = (UserBean (session.getAttribute("currentSessionUser"));%> 

Simply count the number of left and right brackets. But what you look like you want to do is cast

so

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

BTW, maybe better to use EL in your JSP, not java

  • ah~~~ casting! I didn't think of that . thank you very much~ Yup I'll use EL. – Jin Lee Mar 12 at 1:21

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.