The method print(boolean) in the type JspWriter is

2019-02-20 00:49发布

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 :<%= request.getSession(true).setAttribute("state","firstNumber") %>

Here is the code:

`

  <c:when test='${param.event == "NewCall"}'>
      <% 
         Response resp1=new Response();
         CollectDtmf cd= new CollectDtmf(); 
         cd.addPlayText("Welcome. Please enter the first number. Terminate with #");           
         resp1.addCollectDtmf(cd);
      %>
      <%= request.getSession(true).setAttribute("state","firstNumber") %> 
      <% out.println(resp1.getXML()); %>
  </c:when>

`

Please tell what am I doing wrong here. Thanks

1条回答
闹够了就滚
2楼-- · 2019-02-20 01:27

<%= %>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.

查看更多
登录 后发表回答