jsp页面导入java包能干嘛,JSP页面导入问题。 Class文件放在WEB-INF / classes中的一个包中...

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.

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

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 > Add jspider.

crawler_GUI properties > Java EE Module Dependencies > Tick jspider.

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...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值