[英]error while importing .java file in jsp page
I have a .java
file containing a public
class. 我有一个包含
public
类的.java
文件。 It is located under the 'web pages' folder (not under web-inf folder). 它位于“网页”文件夹下(不在web-inf文件夹下)。
On my jsp page I have imported it as: <%@ page import="packagename.javafilename;" %>
在我的jsp页面上,我将其导入为:
<%@ page import="packagename.javafilename;" %>
<%@ page import="packagename.javafilename;" %>
When I run jsp file, I get error as: 当我运行jsp文件时,出现以下错误:
Unable to compile class for jsp.
Only a type can be imported. Packagename.filename resolves to a package
As mentioned in the comments there seems to be a missing % towards the end. 如评论中所述,到最后似乎缺少%。 Here is the way to import classes in jsp
这是在jsp中导入类的方法
// To import one class
<%@ page import="com.xyz.MyClass" %>
OR 要么
// To import multiple classes from the com.xyz package
<%@ page import="com.xyz.*" %>
From your question things are not very clear. 从您的问题来看,事情还不是很清楚。
First of all jsp cannot access .java but a .class file ie you have to keep your code compiled. 首先,jsp 不能访问.java,而只能访问 .class文件,即您必须使代码保持编译状态。
Secondly the class should be in the WEB-INF/classes folder or a jar in WEB-INF/lib folder. 其次,该类应位于WEB-INF / classes文件夹中或WEB-INF / lib文件夹中的jar中。
Use this syntax: 使用以下语法:
<%@ page import="package.filename" %>
In the last import, you might need to add a semicolon after the end of the package.filename. 在最后一次导入中,您可能需要在package.filename的末尾添加分号。 So, if you have like 3 imports, then in the 3rd import line make sure to put a semicolon as:
因此,如果您喜欢3种导入,那么请在第3种导入行中确保输入分号为:
<%@ page import="package.filename;" %>
One more thing, make sure that the class files are in WEB-INF/classes folder. 还有一件事,请确保类文件位于WEB-INF / classes文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.