Error importing JSP page. Class file placed in package inside WEB-INF / classes

I have a working web application crawler_GUI that has another java project of a java project in its build path. (I am using eclipse galileo)

The GUI uses the jspider project as its server.

Visit http://i45.tinypic.com/avmszn.jpg for a structure

JSP creates an instance of the jspider object. First of all, I did not have classes in the WEB-INF / classes folder, and I fixed this error. Now it works, and no errors are displayed, but none of the tasks are performed.

Here is the code:

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); 

Printed * s.

ESpider.java

 public ESpider(URL baseURL) throws Exception { super(baseURL); System.out.println("test"); } 

He does not print a "test." In fact, the parent constructor is not even called. At the same time, errors are not displayed.

How can i fix this?

+1
source share
1 answer

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

Remember to clear any free files in /WEB-INF/classes added manually. It's not needed. Eclipse will take care of this automatically if you specify the projects correctly. In addition, any free JAR files should simply be dumped into /WEB-INF/lib .

Now part of the JSP story. It is difficult to determine the root cause, since you wrote the Java source code in a JSP file instead of the real Java class. The first step is to check the server logs for any inconsistencies. It may also happen that the wrong version of the ESpider class was ESpider (in which sysout is missing).

As already hinted, this is actually not the way you should use JSP. It should be used as a template for writing HTML / CSS / JS, in which you can dynamically control the flow using taglib tags such as JSTL and access the underlying data using EL. Raw Java code belongs to Java classes, not JSP files. In this case, you should have used the Servlet class. Just create the extends HttpServlet class extends HttpServlet , implement the doGet() method, respectively, with the ESpider tag and finally go to the JSP page to display the result, register the servlet in web.xml and call it at the URL that its url-pattern covers in web.xml . You can find many good JSP / Servlet tutorials here .

PS: make sure you understand the robots.txt policy ...

+2
source

Source: https://habr.com/ru/post/1392336/


All Articles