• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets classes not compiling!.

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone,
I am using servlets and jsp to publish a database to an intranet . My problem is that my servlets are not compiling. I am having this error when I complile my servlet :
C:\Tomcat\Tomcat\webapps\CoreData\WEB-INF\classes\ProjectServlet.java:38: package broker does not exist
private broker.RelationBroker rb = broker.RelationBroker.getRelationBroker();
And when I compile a broker class I have this error:
C:\Tomcat\Tomcat\webapps\CoreData\WEB-INF\classes\broker\ProjectBroker.java:157: package core does not exist
core.Project dr = new core.Project();
I have a package called "broker" for my brokers and anpther package called "core' for my bean classes in my classes package. i don't know why it's not compiling.
As a result I can't test my program since when I call my servlet class from my jsp page, the servlet class is not found because it has not been compiled.
Here is how my servlet class looks like:

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ProjectServlet extends HttpServlet
{
//Variables here

private broker.RelationBroker rb = broker.RelationBroker.getRelationBroker();
private Connection con = rb.getConnection();

/*
Description: This method is used to print out the display table
Parameter: HttpServletRequest request
Parameter: HttpServletResponse response
Return: none
*/
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
HttpSession session = request.getSession();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
System.out.println("hi Marcy");
request.setAttribute("session", session);
gotoPage("http://nepru", request, response);

}
// Method to get the request dispatcher and forward the request to the following address
public void gotoPage(String address, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(address);
dispatcher.forward(request, response);
}
// Method to close the db connection.
public void destroy()
{
try{
con.close();}
catch(SQLException sqle){
System.out.println("SQL error" + sqle.getMessage());
sqle.printStackTrace();}
}

I hope I am in the write forum for this.
Please help.Thanks
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marcy KL:
when I complile my servlet :
C:\Tomcat\Tomcat\webapps\CoreData\WEB-INF\classes\ProjectServlet.java:38: package broker does not exist
private broker.RelationBroker rb = broker.RelationBroker.getRelationBroker();
And when I compile a broker class I have this error:
C:\Tomcat\Tomcat\webapps\CoreData\WEB-INF\classes\broker\ProjectBroker.java:157: package core does not exist
core.Project dr = new core.Project();


Have you compiled Project.java file ??
 
Gloria Hans
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All my bean class compiled fine. they are all in my core package. So yes project.java has compiled fine.
My web-inf is organzied as:
web-inf\classes and web-inf\web.xml
classes\broker (contains broker classes)
classes\core (contains bean classes)
classes\servlets classes (not in a package)
The only broker class that compile is my relationalbroker that establishes the connection to the database.
But then I have to call that class from my servlet classes and y other borker classes but it doesn't seem to be able to see that class, or to see my bean classes.
 
R K Singh
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As per your first post, it seems that your ProjectBroker class is not being complied as it does not find Project class.
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marcy,
Wild Guess,
chekc following things
1. package broker; statement appears in RelationBroker.java
2. package core; statement appears in Project.java
3. your classpath has . in it
ex it must be like this c:\blalba;blalba;.;

Cheers
Praful
 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marcy KL:
I am having this error when I complile my servlet :
C:\Tomcat\Tomcat\webapps\CoreData\WEB-INF\classes\ProjectServlet.java:38:


Are you using jdk1.4 or higher version? Try putting your servlet in package, as I remember reading in this forum itself that you need to put your servlet in package for 1.4 or higher version.
 
Gloria Hans
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've added the . in my classpath. I've checked my broker classes and my bean classes(core package), I've also put my servlets in a package but it still doesn't work :roll: .
I've even added the source directory
My code looks like this in my servlet:

public class ProjectServlet extends HttpServlet
{
//Variables

private String pass;
private String url;
private String driver;
private broker.RelationBroker rb = broker.RelationBroker.getRelationBroker();
private Connection con = rb.getConnection();
....
I've addded the source package like this:
private classes.borker.RelationBroker rb= classes.broker.Relation....
but it still doesn't work..
or maybe I am not adding the source package properly?
Pleaaaaaase help
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I realize it's a lot to read, but there are two threads that may help you.

https://coderanch.com/t/354473/Servlets/java/Packages-Utility-Classes-Servlets

That thread contains both the second link, and a more detailed disussion of using the -d switch when compiling at a command line, and how to set up your directories.

I suspect the reason you're not able to compile the servlet, is that you are not building an appropriate -classpath attribute to send to javac.
reply
    Bookmark Topic Watch Topic
  • New Topic