Package Q

2001-04-16 Thread Purcell, Scott

Hello,
I am running the tomcat web server and I am working on Servlets. My install
is on
D:\tomcat\jakarta-tomcat-3.2.2b2
I am working on packages from Suns book, and have had success with creating
a folder called coreservlets under the following path:
D:\tomcat\jakarta-tomcat-3.2.2b2\webapps\ROOT\WEB-INF\classes\coreservlets
and have created some .java files there and have compiled. So I am competent
with my CLASSPATH settings. 

My question:
Now the book is calling (on page 33) two .java files. One calling the other.
The book stated to put both .java files into the coreservlets folder but
does not tell me how to compile this. So I try to compile as if it were a
normal .java file, but the calling file does not find the other file.
eg.
These two files are both sitting in the coreservlets folder, but I get
errors (as if I doesn't see the ServletUtilities.java file);
### file 1
package coreservlets;

import javax.servlet.*;
import javax.servlet.http.*;

public class ServletUtilities {
public static final String DOCTYPE = "";

public static String headWithTitle(String title) {
return (DOCTYPE + "\n" +
"\n" +
"" + title + "\n");
}
}
# file 2
package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWWW3 extends HttpServlet {
public void doGet(HttpServletRequest request,
  HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(ServletUtilities.headWithTitle("Hello") +
"\n" +
"Hello WWW Red\n" +
"");
}
}

But when I compile I get the following error:
 -d
D:\tomcat\jakarta-tomcat-3.2.2b2\webapps\ROOT\WEB-INF\classes\coreservlets
elloWWW3.java
HelloWWW3.java:13: cannot resolve symbol
symbol  : variable ServletUtilities
location: class coreservlets.HelloWWW3
out.println(ServletUtilities.headWithTitle("Hello") +
^
1 error

So that tells me it cannot find the ServletUtilities file?

Could someone try and get me through this?

Thanks
Scott



RE: Package Q

2001-04-16 Thread David McCormick

For starters, do this:

javac HelloWWW3.java ServletUtilities.java

and the compiler will find the ServletUtilities file. Another possibility is
to compile the ServletUtilities file and then include it in your classpath,
either permanently (which you probably don't want to do in this case) or in
the command line compile statement:

javac -classpath %CLASSPATH%;. HelloWWW3.java

assuming ServletUtilities.class is in the current directory (.). That should
get you through the book.

-Original Message-
From: Purcell, Scott [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 16, 2001 3:04 PM
To: '[EMAIL PROTECTED]'
Subject: Package Q


Hello,
I am running the tomcat web server and I am working on Servlets. My install
is on
D:\tomcat\jakarta-tomcat-3.2.2b2
I am working on packages from Suns book, and have had success with creating
a folder called coreservlets under the following path:
D:\tomcat\jakarta-tomcat-3.2.2b2\webapps\ROOT\WEB-INF\classes\coreservlets
and have created some .java files there and have compiled. So I am competent
with my CLASSPATH settings. 

My question:
Now the book is calling (on page 33) two .java files. One calling the other.
The book stated to put both .java files into the coreservlets folder but
does not tell me how to compile this. So I try to compile as if it were a
normal .java file, but the calling file does not find the other file.
eg.
These two files are both sitting in the coreservlets folder, but I get
errors (as if I doesn't see the ServletUtilities.java file);
### file 1
package coreservlets;

import javax.servlet.*;
import javax.servlet.http.*;

public class ServletUtilities {
public static final String DOCTYPE = "";

public static String headWithTitle(String title) {
return (DOCTYPE + "\n" +
"\n" +
"" + title + "\n");
}
}
# file 2
package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWWW3 extends HttpServlet {
public void doGet(HttpServletRequest request,
  HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(ServletUtilities.headWithTitle("Hello") +
"\n" +
"Hello WWW Red\n" +
"");
}
}

But when I compile I get the following error:
 -d
D:\tomcat\jakarta-tomcat-3.2.2b2\webapps\ROOT\WEB-INF\classes\coreservlets
elloWWW3.java
HelloWWW3.java:13: cannot resolve symbol
symbol  : variable ServletUtilities
location: class coreservlets.HelloWWW3
out.println(ServletUtilities.headWithTitle("Hello") +
^
1 error

So that tells me it cannot find the ServletUtilities file?

Could someone try and get me through this?

Thanks
Scott



RE: Package Q

2001-04-19 Thread Danny Angus

perhaps I'm missing something but it looks like:

 out.println(ServletUtilities.headWithTitle("Hello") 

should be  out.println( new ServletUtilities.headWithTitle("Hello")
etc...

or better still..
 ServletUtilities mySU = new ServletUtilities();
out.println(mySU.headWithTitle("Hello") ...etc...

Classes need to be instatiated to create objects, who's methods can then be
invoked.