JSP页面导入问题。 Class文件放在WEB-INF / classes中的一个包中 [英] JSP Page Import problem. Class file placed in a package inside WEB-INF/classes
问题描述
GUI使用jspider项目作为其后端。
访问 http://i45.tinypic。 com / avmszn.jpg 的结构
JSP创建一个jspider对象的实例。首先我没有在WEB-INF / classes文件夹中的类,我纠正了这个错误。现在它似乎工作,没有显示错误,但没有一项任务执行。
这里是代码:
JSP
<%@ page import =net.javacoding.jspider.ESpider,source.Crawler %GT;
<%@ page import =java.net.URL%>
<%// URL baseURL = new URL(Crawler.SelectedSites.get(0));
URL baseURL =新的URL(http://www.buy.com);
System.out.println(******);
ESpider espider = new ESpider(baseURL);
打印*。
ESPider.java
public ESpider(URL baseURL)throws Exception {
super(baseURL);
System.out.println(test);
}
它不打印测试 。实际上,父进程的构造函数甚至不被调用。同时也不会显示任何错误。
我该如何解决?
在Eclipse中,您需要将 jspider
crawler_GUI
项目如下:
-
crawler_GUI
属性> Java构建路径>项目>添加jspider
。 -
crawler_GUI
属性> Java EE模块依赖关系> Tickjspider
。
Don不要手动清除 / WEB-INF / classes
中的任何松散的文件。这是不必要的如果您以正确的方式引用了项目,Eclipse将自动关注此问题。此外,任何松散的JAR文件都应该被放在 / WEB-INF / lib
中。
现在JSP部分故事。由于您在JSP文件而不是真正的Java类中编写了原始的Java代码,所以很难确定根本原因。第一步是检查服务器日志是否存在任何不一致。也可能发生错误版本的 ESpider
类已经加载(缺少sysout)。
扩展HttpServlet 的类,然后使用 ESpider实现
的东西,最后转发到一个JSP页面来显示结果,在 doGet()
方法 web.xml
中注册servlet,并通过URL来覆盖它的 url-pattern
在 web.xml
中。 您可以在这里找到很多很好的JSP / Servlet教程。
PS:确保您了解 robots.txt
政策...
I have a Web application crawler_GUI running which has another java project jspider in its buildpath. (I use eclipse galileo)
The GUI uses the jspider project as its backend.
Visit http://i45.tinypic.com/avmszn.jpg for the structure
The JSP creates an instance of the jspider object. First of all I didn't have the classes in the WEB-INF/classes folder and I rectified that error. Now it seems to work, and no errors are shown but none of the tasks are carried out.
Here's the code :
The JSP
<%@ page import = "net.javacoding.jspider.ESpider, source.Crawler"%>
<%@ page import = "java.net.URL" %>
<%//URL baseURL = new URL(Crawler.SelectedSites.get(0));
URL baseURL = new URL("http://www.buy.com");
System.out.println("******");
ESpider espider = new ESpider(baseURL);
The *s get printed.
ESpider.java
public ESpider(URL baseURL) throws Exception {
super(baseURL);
System.out.println("test");
}
It doesn't print "test". In fact the parent's constructor isn't even being called. At the same time no errors are displayed either.
How can I fix this?
In Eclipse, you need to add the jspider
project to the crawler_GUI
project as follows:
crawler_GUI
properties > Java Build Path > Projects > Addjspider
.crawler_GUI
properties > Java EE Module Dependencies > Tickjspider
.
Don't forget to cleanup any loose files in /WEB-INF/classes
you've added manually. This is unnecessary. Eclipse will automagically take care about this if you referenced the projects the right way. Also, any loose JAR files are supposed to be just dropped in /WEB-INF/lib
.
Now the JSP part of the story. It's hard to pinpoint the root cause since you wrote raw Java code in a JSP file instead of a real Java class. First step would be checking the server logs for any inconsistencies. It may also have happened that the wrong version of the ESpider
class has been loaded (which lacks the sysout).
As already hinted, this isn't really the way you're supposed to use JSP. It is to be used to as a template to write HTML/CSS/JS in wherein you can dynamically control the flow with help of taglibs like JSTL and access backend data using EL. Raw Java code belongs in Java classes, not JSP files. In this case you should have used a Servlet class. Just create a class which extends HttpServlet
, implement the doGet()
method accordingly with the ESpider
stuff and finally forward to a JSP page to display the result, register the servlet in web.xml
and call it by URL which covers its url-pattern
in web.xml
. You can find here a lot of good JSP/Servlet tutorials.
P.S: ensure that you understand the robots.txt
policy...
这篇关于JSP页面导入问题。 Class文件放在WEB-INF / classes中的一个包中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!