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

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

2013-09-11 
。。。菜鸟问题。。。Java code页面代码:%SmartUpload mysmartload new SmartUpload()long file_size_max10*

。。。菜鸟问题。。。

Java code
    页面代码:             <%       SmartUpload mysmartload =new SmartUpload();     long file_size_max=10*1024*1024;    String filename=""; // 文件名     String ext="";   //后缀名    String testVal ="";  //    String url="Images/";   // 保存文件目录    mysmartload.initialize(pageContext); // 初始化        try {       mysmartload.setAllowedFilesList("jpg,gif,png,jpeg,bmp"); // 允许上传的文件类型        mysmartload.upload();           }        catch(Exception  e) {           %>          <script language="javascript">  alert("只允许上传.jpg和.gif类型图片文件");  </script>   <%      }     try  {   com.jspsmart.upload.File myfile = mysmartload.getFiles().getFile(0);           if(myfile.isMissing())               {                 %>                  <script language="javascript">alert("请先选择要上传的文件");</script>                 <%                  }                 else                  { String myfilename=myfile.getFileName(); // 获取上传文件的文件名  ext=myfile.getFileExt(); // 获取上传文件的后缀名  int file_size=myfile.getSize(); // 获取上传文件的大小String savaurl="";  if(file_size<file_size_max) { savaurl = application.getRealPath("upload/")+url;  savaurl+= filename+"."+ext; // 文件全名     // 保存路myfile.saveAs(savaurl,SmartUpload.SAVE_PHYSICAL); // 输出  Out.print()  }  }catch (Exception ex){       System.out.print(ex.toString());         }   %> 错误异常: org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 15 in the generated java fileOnly a type can be imported. com.jspsmart.upload.File resolves to a packageAn error occurred at line: 14 in the jsp file: /WebRoot/Uploadfile.jspSmartUpload cannot be resolved to a type11: 12: <% 13:   14:     SmartUpload mysmartload =new SmartUpload();   15:       16:     long file_size_max=10*1024*1024; 17:        An error occurred at line: 14 in the jsp file: /WebRoot/Uploadfile.jspSmartUpload cannot be resolved to a type11: 12: <% 13:   14:     SmartUpload mysmartload =new SmartUpload();   15:       16:     long file_size_max=10*1024*1024; 17:        An error occurred at line: 48 in the jsp file: /WebRoot/Uploadfile.jspcom.jspsmart.upload.File cannot be resolved to a type45:          } 46:          try 47:          { 48:            com.jspsmart.upload.File myfile = mysmartload.getFiles().getFile(0); 49:               if(myfile.isMissing()) 50:               { 51:                 %> An error occurred at line: 78 in the jsp file: /WebRoot/Uploadfile.jspSmartUpload.SAVE_PHYSICAL cannot be resolved to a type75:                           76:                            // 保存路径77:                           78:                           myfile.saveAs(savaurl,SmartUpload.SAVE_PHYSICAL); 79:                           80:                           81:                           // 输出Stacktrace:    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)    org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)    org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)    org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)    javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 

 


 哪位大神帮看一看... 
  
   


 

------解决方案--------------------
SmartUpload ,
com.jspsmart.upload.File 
这两个类都认不到,你在jsp最上面没引入啊?
------解决方案--------------------
error occurred at line: 14 in the jsp file: /WebRoot/Uploadfile.jsp
SmartUpload cannot be resolved to a type

SmartUpload.SAVE_PHYSICAL cannot be resolved to a type

SmartUpload.SAVE_PHYSICAL 不能识别,没有引入这个类的包。
------解决方案--------------------
仔细检查下引入包的问题

------解决方案--------------------

1,检查是否将classpath设置错误:正确的为.;%java_home%/lib/rt.jar;%java_home%/lib/tools.jar <!--java_home is your jdk directory-->
2,This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK
to the common/lib directory of the Tomcat server, followed by a Tomcat restart.
看到了吗?
把jdk安装目录下的lib/tools.jar拷贝到tomcat安装目录下的common/lib目录下,然后重启tomcat,试试 。
3,设置tomcat的字符集为GBK,预防乱码的产生:F:/Tomcat 5.0/conf目录下的server.xml中增加一个参数URIEncoding="GBK",或者统一"utf-8"编码
for example: <Connector URIEncoding="GBK"
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" />
4,增大tomcat的jvm内存使用参数:在F:/Tomcat 5.0/bin目录下的catalina.bat文件中增加set JAVA_OPTS=-Xms256m -Xmx512m

总之,以上是引起 org.apache.jasper.JasperException: Unable to compile class for JSP 顶层异常最常见的原因,其他底层异常也会造成此异常,是具体情况而定;
------解决方案--------------------

JScript code
 enctype= "multipart/form-data "

 

 

热点排行