[英]The method print(boolean) in the type JspWriter is not applicable for the arguments (void)
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. 嗨,我在GAE中遇到了一个名为“类型为JspWriter的方法print(boolean)不适用于参数(void)”的错误。
In line : <%= request.getSession(true).setAttribute("state","firstNumber") %>
在以下行中:
<%= 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
谢谢
<%= %>
expects an expression, whose value is printed to the JSP's writer. <%= %>
需要一个表达式,其值将打印到JSP的编写器中。 The following 下列
<%= foo %>
is thus equivalent to 因此等于
out.print(foo);
request.getSession(true).setAttribute("state","firstNumber")
is an expression whose type is void. 是一个类型为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. 但是,当然,由于无数次被重新定义,因此不应在JSP中使用scriptlet。 JSPs are view components which should only generate HTML using the JSP EL, the JSTL and other custom tags.
JSP是视图组件,仅应使用JSP EL,JSTL和其他自定义标签生成HTML。 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.
更不用说设置会话属性通常是一个坏主意,在视图组件中更是个坏主意,除了打印到JSP编写器之外,它不会有任何副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.