简体   繁体   English

将Java类导入JSP

[英]Importing java classes into JSP

That's the problem. 那就是问题所在。

I developed a web app with NetBeans 7 , Tomcat 7 and hsqldb ; 我使用NetBeans 7Tomcat 7hsqldb开发了一个Web应用程序; on my desktop all is Ok. 在我的桌面上一切正常。

When I upload my java files (.class, .jsp and .jar packages) to my site and try to load a jsp page which imports a class contained in a package (class FunzioniSessione in package it.swlab.util ), I get the following error: 当我上传我的java文件(的.class,.JSP和.jar包)到我的网站,并尝试加载一个JSP页面其中进口含有类的包(类FunzioniSessione在包it.swlab.util ),我得到的以下错误:

org.apache.jasper.JasperException: Unable to compile class for JSP:  
An error occurred at line: 6 in the generated java file 
Only a type can be imported. it.swlab.util.FunzioniSessione resolves to a package 

An error occurred at line: 7 in the jsp file: /index.jsp 
FunzioniSessione cannot be resolved to a type 
4: <% 
5: synchronized(this) 
6: { 
7: FunzioniSessione funzioniSessione = new FunzioniSessione(); 
8: String percorso = config.getServletContext().getRealPath("/"); 
9: funzioniSessione.inizializza(session,request,response,percorso,"infocar"); 
10: boolean connesso = session.getAttribute("utenteConnesso") != null; 

An error occurred at line: 7 in the jsp file: /index.jsp 
FunzioniSessione cannot be resolved to a type 
4: <% 
5: synchronized(this) 
6: { 
7: FunzioniSessione funzioniSessione = new FunzioniSessione(); 
8: String percorso = config.getServletContext().getRealPath("/"); 
9: funzioniSessione.inizializza(session,request,response,percorso,"infocar"); 
10: boolean connesso = session.getAttribute("utenteConnesso") != null; 

Stacktrace: 
 org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93) 
 org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) 
 org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:451) 
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:328) 
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:307) 
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:295) 
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:565) 
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:309) 
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308) 
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259) 
 javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 

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

To prevent some obvious answers, I add some more information: 为了避免出现明显的答案,我添加了更多信息:

  1. The package containing the class FunzioniSessione (named funzioniComuni.jar ) is in the WEB-INF\\lib folder 包含类FunzioniSessione的程序包(名为funzioniComuni.jar )位于WEB-INF\\lib文件夹中
  2. I can't look at the logs as the note in the stacktrace suggests, because I have no access to the logs folder of my provider's Tomcat server. 我无法查看堆栈跟踪中的注释所建议的日志,因为我无权访问提供者的Tomcat服务器的logs文件夹。 3 The directive for the import is <%@page import="it.swlab.util.FunzioniSessione"%> I tried also with a ";" 3导入指令为<%@page import="it.swlab.util.FunzioniSessione"%>我也尝试过使用“;” at the end ( <%@page import="it.swlab.util.FunzioniSessione;"%> ) but with no success. 最后( <%@page import="it.swlab.util.FunzioniSessione;"%> )),但没有成功。

I wait for some suggestions. 我等待一些建议。

Thank you 谢谢

Is the FunzioniSessione on you classpath ? 是您的classpath上的FunzioniSessione吗? Generally we keep the classes in web-inf\\classes which is already onclasspth. 通常,我们将类保存在已经onclasspth的web-inf \\ classes中。 Can you ensure the deployment directory has this structure with you class in expected package ? 您可以确保预期目录中的类具有部署目录吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM