• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Head first sample code

 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on the Chapter three example. I am trying to compile my BeerSelect.java file and I get these errors:

"package javax.servlet does not exist" for my import javax.servlet.* line
and
"package javax.servlet.http does not exist" for my import javaxservlet.http.* line.

I get other "cannot resolve symbols" errors but they come from package error.

I went back to the chapter one sample and it works if I enter
javac - classpath d:tomcat/common/lib/servlet-api.jar -d classes src/Ch1Servlet.java

I can get it to fail the same way if I leave off the "d:" in front of d:tomcat/common/lib/servlet-api.jar

I am working in Win2K.

I am in the d:/MyProjects/beerV1 folder and here is the actual command line I am trying to use.

javac -classpath d:tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java

Thanks in advance.

Tim Rawerts
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

try this on Windows:



Do you see it . You must change : with ; and use backslash

Regards,
Darya
[ August 03, 2005: Message edited by: Darya Akbari ]
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I will try, but why do the forward slashes work for the Chapter one example?
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
replacing the colon with the semi-colon seemed to take care of the problem. The forward slashes don't seem to be a problem. I had thought about that, and I should probably play with it, but that will have to be at a later date.

Thanks again for your help!!!

Tim Rawerts
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, curiosity got the better of me

It doesn't matter if the slashes are forward slashes or back slashes, my file compiled into a class either way.

Thanks again!

Tim Rawerts
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boy this has been a long day

I copied my class to the /Beerv-1/WEB-INF/classes/com/example/web folder in the deployment structure, and when I try to test it out I get this:

HTTP Status 404 - /Beer-v1/form.html

--------------------------------------------------------------------------------

type Status report

message /Beer-v1/form.html

description The requested resource (/Beer-v1/form.html) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.2


All files appear to be where they are supposed to be. Any ideas?

Tim Rawerts
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

there are more of these long days to come . Let's talk about development and deployment environments. Where in your deployment did you place your form.html page?

Regards,
Darya
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For deployment, I have put my form.html under d:\tomcat\webapps\Beer-v1. It is at the same level as the WEB-INF folder.

Thanks again for your help Darya. I did not use these forums much for the SCJP, but it has already been a life saver for the SCWCD. And I am sure you are right, I will have many "head banging" days ahead.

Tim Rawerts
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

your form.html is in the right place. Do you see any exceptions in your tomcat window during tomcat start up?

Regards,
Darya
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Tomcat appears to start properly. Everything else worked up to this point.

The last thing that worked was testing the page (#4 on page 76). The only things after that were the DD, and compiling the Servlet. The servlet compiles and since we don't even call the html I doubt it has anything to do with it. Would it be a good assumption that I did something wrong with my web.xml file?

I will go back over it and see if I fat fingered something.

Thanks again.
Tim Rawerts
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that you try to open your page with http://localhost:8080/Beer-v1/form.html.

Your web.xml Deployment Descriptor (DD) belongs in your deployment WEB-INF directory.

On the other hand make sure that you follow each bit and byte of HFSJ's description for the Beer-v1 application, because all next exercises follow the same rules.

Regards,
Darya
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again. It appears I am using the correct syntax for the url. I really can't (shouldn't) go forward until I figure this out. I will go over every detail with a fine tooth comb and see what I can come up with.

Tim Rawerts
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you should make this one your reference for every new web app to come.

Good Luck
Darya
 
ramaseshan T
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't go through the full thread..One mistake what I did was: Double clicking the form.html without typing the URL direcly on the webbrowser:
http://localhost:8080/Beer-v1/form.html

It didn't workout..I was banging my head for nearly an hour
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I have been entering the url by hand. I see another thread that looks similar, so I will look at that. If I can't figure it out, then I am going to delete it all and start over.........




Thanks again.
Tim Rawerts
 
Tim Rawerts
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for all your help! I deleted everything and executed the exercise again and I got it to work!!!

These little successes in life keep us going!

Tim Rawerts

Oh yeah, it is time for a beer!
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers!

Regards,
Darya
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am having the very same problem.
I have linux and tomcat 5.

When I replace : with ; like that:


I get the following error:


Please tell me what is wrong.
 
Bert Bates
author
Sheriff
Posts: 8905
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first thing is to take out the space in front of the word 'servlet'

hth
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
gee ... thanx
In the book the line wrapped before the 'servlet' and because it was my first time compileing a servlet I accidently assumed it was a space there.
 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, but after submitting the form, i get 404 error for /~juhan/test/SelectBeer.do

I assume this is because of web.xml not beeing 100% right?
 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Juhan,
You are just doing ok.
I followed your head hitting problems. I had the same problems
too initially. I had to drop the book for some days.
The first thing is that OS handle their file system
differently, i use winXP. When linux say :, win will say ;
Right.
So, Check your web.xml and make sure, the
<servlet-name>specified when declearing the name</servlet-name>
matches
the name specified in the servlet name of the servlet mapping (exact name)
Also, make sure the form action name is the same with the name specified
in the
<url-pattern>/select.do</url-pattern>

So keep coding, see you at the other end.

SCJP 1.4 SCJA 1.0 SCWCD( progressing)

 
Juhan Voolaid
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again

I got it working back there - thank you everyone, but now I have another question about that ...


What does this line "-classpath usr/local/tomcat/common/lib/servlet-api.jar:classes:." really say/do?

Do I have to compile that way simple javaBean classes allso?

What about if I am using Struts and I compile those Action and form classes?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic