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