首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

求助一个Jsp有关问题

2013-09-11 
求助一个Jsp问题源文件是:gaods1.jsp%@ page contentTypetext/htmlCharsetGB2312%htmlbody bgco

求助一个Jsp问题


源文件是:
gaods1.jsp

<%@ page contentType="text/html;Charset=GB2312"
 %>
<html><body bgcolor=yellow>
 <p> 加载一个jsp文件,该文件负责计算连续整数之和:
  <jsp:include page="computer.jsp">
  <jsp:param name="item" value="100" />
 </jsp:include>
</body></html>

computer.jsp
<%@ page contentType="text/html;Charset=GB2312"  

language="java" import="java.sql.*" errorPage="" 

%>
<html><body>
 <% String str=request.getParameter("item");
  if( str==null)
  str=" ";
  int n=Interger.parseInt(str);
  int sum=0;
  for(int i=1;i<=n;i++)
  sum=sum+i;
}
  out.println("<br> 从1~"+n+"的连续和是:</br>"+sum);
%>
</body></html>


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: -1 in the jsp file: null

Generated servlet error:
  [javac] Compiling 1 source file

C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ch01\computer_jsp.java:30: 'try' without 'catch' or 'finally'
  try {
  ^
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ch01\computer_jsp.java:53: illegal start of type
  } catch (Throwable t) {
  ^
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ch01\computer_jsp.java:63: expected
  }
  ^
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ch01\computer_jsp.java:64: 'class' or 'interface' expected
}
^
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\ch01\computer_jsp.java:65: 'class' or 'interface' expected
^
5 errors


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:552)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:1002)
org.apache.jsp.ch01.gaods1_jsp._jspService(gaods1_jsp.java:42)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.



[解决办法]


<%@ page contentType="text/html;Charset=utf-8"%>


<html> <body bgcolor=yellow>
<p> 
<jsp:include page="computer.jsp" >
<jsp:param name="item" value="100"/>
</jsp:include >
</body > </html > 



<%@ page contentType="text/html;Charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<body>
<% 
String str=request.getParameter("item");
if(str==null)
str=" ";
int n=Integer.parseInt(str);
int sum=0;
for(int i=1;i<=n;i++)
sum=sum+i;
out.println("sum:"+sum);
%>
</body>
</html>

[解决办法]
for(int i=1;i <=n;i++) 
sum=sum+i; 


少了个大括号
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

热点排行