您好,我在 GAE 中的 JSP 代码中遇到名为“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 的 View 组件。更不用说设置 session 属性通常是一个坏主意,在 View 组件中更是一个坏主意,除了打印到 JSP 编写器之外,它不应该有任何副作用。
关于java - JspWriter 类型中的方法 print(boolean) 不适用于参数 (void),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23459584/