Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing Servlet3.java - Errors

 
Gina Mein
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to compile Servlet3.java and got a compilation error saying:
"Undefined variable or Class name:ServletUtilities"
I understand that I have to include development directory in my classpath.
1) My development directory is:
C:\Gina\WebDeveloper
2) servlet.jar is installed in
C:\tomcat4\bin\common\lib
3) My classpath seting is as follows:
SET CLASSPATH=.;C:\Gina\WebDeveloper;C:\tomcat\bin\common\lib\servlet.jar
I have followed the instructions from Marty Hall's book and website.
Can anyone guess what could be wrong? I would greatly appreciate it.
Thanks.
 
mary nathan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Gina
what is your ServletUtilities file ?
did you copy it from web site ? or did u
have your own ServletUtilities file ?
make sure that the ServletUtilities file exist.
or else you can use the code given in the
book(Marty Hall).
thanks
mary
 
Gina Mein
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mary:
Thanks for responding.
I downloaded the ServerUtilities file from 'moreservlets.com'. It resides in my development directory ie
"C:\Gina\WebDeveloper". HelloServlet3.java also resides in the same directory.
When I try to compile the servlet file, it gives me an eror saying "class or variable not found: ServerUtilities not found".
Is there any other location, where I should put my serverutilities.java/class file?
Thanks
 
mary nathan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Gina
is it ServletUtilities ? or ServerUtilities ?
i think it is "ServletUtilities .java" file.
did you notice the contents of this file ?
they are noway related to HelloWorld3.java.
but the contents of HelloWorld3.java is same
in the book as well as in the website.
anyway, this 'ServletUtilities' file that is in the web site and the one in the book are different.that is what i noticed.
so i used the code given in the book.(page 33)
since he is talking about packages in that example you have to create a sub directory (same as the package name )in
your c:\Gina\WebDeveloper development directory.
you also have to create a sub directory(same as the package name) in the classes directory then put your class files.
thanks
mary
 
Gina Mein
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!Mary
Thanks!
It worked!!!
You were right, the ServletUtilities file was different from the book. I rewrote it and it worked!!!
Thanks again.
Now I can get to the real business of writing my own Servlets...
 
taash mg
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey mary and gina,
could u please give me the code for the correct ServletUtilities.java file. i don't have the book so i cannot correct it please..
Thanks
Taash
 
mary nathan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi taash
this is the code for ServletUtilities.java.
//////////////////////////
package pack;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletUtilities
{
public static final String DOCTYPE =
"<! DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\"> ";

public static String headWithTitle(String title)
{
return( DOCTYPE +"\n" + "<HTML> \n" +
" <HEAD><TITLE>" +title + "</TITLE></HEAD>\n");
}
}
////////////////////////////////////////////
thanks
mary
 
taash mg
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mary
thanks a lot for the code. i have corrected my file.

Cheers
Taash
 
taash mg
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mary,
I corrected file still doesn't work with the HelloServlet3.java class. i get

i don't know whats wrong..can u help please?
Thanks
Taash
 
mary nathan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi taash
i think your package name is 'sunskriti'.
hope you have created the subdirectory 'sunskriti' and put both 'ServletUtilities' and 'HelloServlet3.java'
in the same subdirectory.
you should also include
package sunskriti; as the first
statement in both the files.
then compile and see.
thanks
mary
 
taash mg
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mary,
i have both my files under in my package i.e my directory and also have the first line as package sunskriti; but no results..
cheers
taash
 
mary nathan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi taash
can you show me the code you are using for both the files ? and also what is your working
directory ? (does it look like this ?c:\servletjsp\sunskriti ?)
thanks
mary
 
taash mg
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mary,
My files are under C:\<tomcat-home>\webapps\Root\WEB-INF\classes\sunskriti\...
here are both my files...

****************************


Thanks
Taash
 
mary nathan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi taash
why don't you create a directory like this
c:\servletjsp\sunskruti and put your java files in this ?
then compile from this same directory ,take the
.class files(HelloServlet3.class,ServletUtilities.class)
and put them in
C:\<tomcat-home>\webapps\Root\WEB-INF\classes\sunskriti
i got the result when did like that.
thanks
mary
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This exact problem was discussed in the Servlets forum.

Here:
http://www.coderanch.com/t/354453/Servlets/java/Unable-compile-package
and here:
http://www.coderanch.com/t/354473/Servlets/java/Packages-Utility-Classes-Servlets

With respect to all other posters... my solution solves this entire class of problem ( 'cannot resolve symbol' and/or 'undefined variable or class name: xxxxx ')
 
taash mg
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Mike

Thanks a lot for the wonderful description and information. it finally worked after munching a whole lot of my brain

Taash
 
taash mg
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mary,
Thanks a lot for all ur efforts and help too.
Cheers
Taash
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem taash,
The classpath thing always messes people up, even myself many times. I use an IDE for a lot of work, and it handles all of that for me. But ocassionaly I'll use TextPad, or someone else who doesn't use an IDE will ask me "what's this error mean?" and I'll have to re-learn that mistake all over again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic