这段JSP代码为何有错.?

来源:百度知道 编辑:UC知道 时间:2024/05/25 07:40:13
简单的一段JSP代码:却抛出一大堆的Exceptions异常.。
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 43 in the jsp file: /Print.jsp
Generated servlet error:
The method print(boolean) in the type JspWriter is not applicable for the arguments (void)

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Comp

在jap中使用System.out.println()是没有什么意义的。输出的话可以使用out.print().
方法public void Get()返回值为空,
而<%=Get() %> 是接收get()方法的返回值。
我帮你改了下:
<%@ page contentType="text/html;charset=gbk"%>

<%!
public String geMessage() {
return "1--20的偶数";
}
%>

<html>
<head>
<title>输出1-20的偶数</title>
</head>
<body>
<%=geMessage()%><br/>
<%
for(int i = 1 ;i <= 20 ; i++){
if(i%2==0){
%>
<%=i%><br/>
<%
}else
continue;
}
%>
</body>
</html>

<%=Get() %> 这句话不正确...因为Get()是一个 void 类型的函数..

不返回任何值....所以不能用<%=Get() %>输入返回的结果...去掉就正确了..

如果还是有问题的话...

百度HI我...帮你解决...

祝楼主早日成功!!!

直接 <%Get();%> 去掉=

在JSP中, <%= %>标签会对标签中的内容进行求值, 之后将值