简体   繁体   English

如何将自己的类添加到JSP页面?

[英]How to add my own class to a JSP page?

I'm trying to add a Java class to a jsp page but for some reason it's not working. 我试图将Java类添加到jsp页面,但是由于某种原因,它无法正常工作。 我收到错误

JSP页面

文件层次

类本身。代码很好,没有任何错误。

The error I'm getting: 我得到的错误:

The JSP page The project hierarchy the class itself. JSP页面项目层次结构是类本身。 There are no erros in the class's code. 该课程的代码中没有错误。

Well, turns out that the solution is really simple. 好吧,事实证明,解决方案非常简单。
If you're creating a class for your project you need to put the filename.java file inside a new package in the Test Packages folder in your main project. 如果要为项目创建类,则需要将filename.java文件放入主项目中“测试软件包”文件夹中的新软件包中。
Here is how it looks after moving the java file - 这是移动Java文件后的样子-

在此处输入图片说明 This is a solution for Netbeans as far as I tried. 就我所试,这是针对Netbeans的解决方案。 Can't belive it took me hours to solve it. 不能相信我花了数小时才解决它。

FYI, the Test Packages is for testing purposes; 仅供参考, 测试包用于测试; one should use the Source Packages as shown below: 一个人应该使用如下所示的源代码包

在此处输入图片说明

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

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