Java 类不可访问
我正在尝试使用 Eclipse Helios 构建一个动态 Web 应用程序。我正在尝试在 jsp 页面中使用 java 类。该页面在编码和部署期间可见。在运行时,java 类不会解析为类型。为什么会出现这种情况?
更新: 目录结构与 eclipse 相同
Restarunt JAX-WS Web Services
Deploymment Descriptor Java
Resources:src
default package
LoginBean build WebContent WebINF
lib
web.xml
weblogic.xml jsp files
I am trying to build a dynamic web app using Eclipse Helios. I am trying to use a java class inside a jsp page. The page is visible during coding and deployment. In the runtime the java classes are not resolved to a type. Why does this happen?
Update:
Directory structure as in eclipse
Restarunt JAX-WS Web Services
Deploymment Descriptor Java
Resources:src
default package
LoginBean build WebContent WebINF
lib
web.xml
weblogic.xml jsp files
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认包中的类对于包中的类不可见/无法导入。 JSP 文件最终作为包中的类,因此它对于 JSP 也是不可见的。这仅适用于非常特定的(Tomcat)环境,您不想依赖于此。只需将类放入包中即可。总是。
与该问题无关,在 JSP 中编写 Java 代码是一种糟糕的做法< /a>.使用 Servlet。
Classes in the default package are invisible/unimportable by classes in a package. JSP files end up as a class in a package, so it will be invisible to JSP as well. This works in very specific (Tomcat) environments only, you don't want to be dependent on that. Just put classes in a package. Always.
Unrelated to the problem, writing Java code in a JSP is a poor practice. Use a Servlet.
您是否在jsp中添加了这些类,这些类位于类路径中或构建后位于
WEB-INF/classes
中Have you added in jsp, and this classes are in class path or is in the
WEB-INF/classes
after build如果您的类的 FQN 是
your.package.YourClass
那么请确保您的类部署到:If FQN of your class is
your.package.YourClass
then make sure your class deploys to: