繁体   English   中英

JspWriter类型的方法print(boolean)不适用于参数(void)

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

嗨,我在GAE中遇到了一个名为“类型为JspWriter的方法print(boolean)不适用于参数(void)”的错误。

在以下行中: <%= request.getSession(true).setAttribute("state","firstNumber") %>

这是代码:

`

  <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>

`

请在这里告诉我我在做什么错。 谢谢

<%= %>需要一个表达式,其值将打印到JSP的编写器中。 下列

<%= foo %>

因此等于

out.print(foo);

request.getSession(true).setAttribute("state","firstNumber")

是一个类型为void的表达式。 而且您不能打印空白。

您想要的只是

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

但是,当然,由于无数次被重新定义,因此不应在JSP中使用scriptlet。 JSP是视图组件,仅应使用JSP EL,JSTL和其他自定义标签生成HTML。 更不用说设置会话属性通常是一个坏主意,在视图组件中更是个坏主意,除了打印到JSP编写器之外,它不会有任何副作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM