It's not a secret anymore!*
The moose likes Servlets and the fly likes Servlets classes not compiling!. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets classes not compiling!." Watch "Servlets classes not compiling!." New topic
Author

Servlets classes not compiling!.

Gloria Hans
Greenhorn

Joined: Nov 06, 2003
Posts: 18
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
R K Singh
Ranch Hand

Joined: Oct 15, 2001
Posts: 5371
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 ??


"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Gloria Hans
Greenhorn

Joined: Nov 06, 2003
Posts: 18
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

Joined: Oct 15, 2001
Posts: 5371
As per your first post, it seems that your ProjectBroker class is not being complied as it does not find Project class.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 640
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


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
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.


- Varun
Gloria Hans
Greenhorn

Joined: Nov 06, 2003
Posts: 18
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
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I realize it's a lot to read, but there are two threads that may help you.

http://www.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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets classes not compiling!.