The method print(boolean) in the type JspWriter is not applicable for the arguments (void)

前端 未结 1 743
猫巷女王i
猫巷女王i 2021-01-15 03:56

Hi I am facing a error named \"The method print(boolean) in the type JspWriter is not applicable for the arguments (void) \" with my JSP code in GAE.

In line :

相关标签:
1条回答
  • 2021-01-15 04:22

    <%= %>expects an expression, whose value is printed to the JSP's writer. The following

    <%= foo %>
    

    is thus equivalent to

    out.print(foo);
    
    request.getSession(true).setAttribute("state","firstNumber")
    

    is an expression whose type is void. And you can't print a void.

    What you want is simply

    <% request.getSession(true).setAttribute("state","firstNumber") %>
    

    But of course, as it has been rehashed countless times, scriptlets should not be used in a JSP. JSPs are view components which should only generate HTML using the JSP EL, the JSTL and other custom tags. Not to mention that setting session attributes is, in general, a bad idea, and is even more a bad idea in a view component, which shouldn't have any side effect other than printing to the JSP writer.

    0 讨论(0)
提交回复
热议问题