JspWriter类型中的print(boolean)方法不适用于参数(void) [英] The method print(boolean) in the type JspWriter is not applicable for the arguments (void)

查看:4217
本文介绍了JspWriter类型中的print(boolean)方法不适用于参数(void)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正面临一个错误,名为JspWriter类型中的方法print(boolean)不适用于GAE中我的JSP代码的参数(void)。

行:<%= request.getSession(true).setAttribute(state,firstNumber)%>



以下是代码:

`

 < c:when test ='$ {param.event ==NewCall}> 
<%
响应resp1 = new Response();
CollectDtmf cd = new CollectDtmf();
cd.addPlayText(Welcome。请输入第一个数字,终止于#);
resp1.addCollectDtmf(cd);
%>
<%= request.getSession(true).setAttribute(state,firstNumber)%>
<%out.println(resp1.getXML()); %GT;
< / c:当>

`



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

解决方案

<%=%> 其值被打印到JSP的作者。以下

 <%= foo%> 

因此相当于

 的out.print(FOO); 

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

是一个表达式,其类型为void。而且你不能打印空白。

你想要的只是简单的

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

但是,当然,因为它已被无数次地重新编译,所以scriptlet不应该用在JSP中。 JSP是视图组件,只能使用JSP EL,JSTL和其他自定义标记生成HTML。更不用说,设置会话属性通常是一个坏主意,在视图组件中更糟糕的是,除了打印到JSP书写器之外,它不应该有任何副作用。


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

解决方案

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

这篇关于JspWriter类型中的print(boolean)方法不适用于参数(void)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆