File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Head first Servlets first example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Head first Servlets first example" Watch "Head first Servlets first example" New topic
Author

Head first Servlets first example

Sandro Cassandro
Greenhorn

Joined: Aug 08, 2011
Posts: 4
Hey guys, im learning servlets and have decided to do it oldways - that is, with using javac as a compiler and creating folders and files manually instead of Netbeans or Idea doing it all for me and deploying the thing.

I've got Tomcat 7.0, it works, it displays localhost, i could login in the manager, my app is not there and i don't know how to deploy it, whether i should deploy it or it should just work.

Ch1Servlet.java


web.xml


I haven't really understood a thing about invoker but i have a feeling it's aight here, since i haven't embedded something right into GET or POST.

My directories' placement is as follows: \tomcatdir\webapps\ROOT\ch1\WEB-INF\classes\pk1
Ch1Servlet.class is a compiled class, it's in pk1 directory.
web.xml is as listed above and it's in WEB-INF directory.

I try to run the stuff as this: http://localhost:8080/ch1/Serv1
I get the error: The requested resource (/ch1/Serv1) is not available.


Why is that and how can i correct it? Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Sandro Cassandro wrote:my app is not there and i don't know how to deploy it, whether i should deploy it or it should just work.

Of course you need to deploy it. Tomcat can't just know anything about it. Easiest way is to create a war file and copy it to the webapps folder.

I haven't really understood a thing about invoker

The only thing you need to know about the invoker is that it is not to be used. Ever.

My directories' placement is as follows: \tomcatdir\webapps\ROOT\ch1\WEB-INF\classes\pk1

Wrong. You should never place anything under ROOT. That's the ROOT web app. you don't deploy by writing into another web app. You should either use a war file, or place your context root in webapps. Not ROOT.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sandro Cassandro
Greenhorn

Joined: Aug 08, 2011
Posts: 4
Of course you need to deploy it.

Understood and done. It's in manager app list now, listed at path /ch1.

I've created WAR with contents of ch1, i've deployed it, it added META-INF dir inside, so i got two directories inside ch1 at webapps - META-INF and WEB-INF with web.xml and classes directory with my .class file inside its pk1.


Still, i get the same error trying http://localhost:8080/ch1/Serv1

UPD: My bad, haven't noticed it, it says in app manager that it's not running and when i try to start it, i get FAIL - Application at context path /ch1 could not be started.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Look in the logs for the failure information.
Sandro Cassandro
Greenhorn

Joined: Aug 08, 2011
Posts: 4
Ok, i've found a different web.xml and with that one my thing works. Here's the original one:


Here's the one i'm using right now and it works:



So the only thing that is different is encoding stuff, no actual tricky syntax? How could that be?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Sandro Cassandro wrote:So the only thing that is different is encoding stuff

That's the only difference you see?

And please, fix the indentation.
Sandro Cassandro
Greenhorn

Joined: Aug 08, 2011
Posts: 4
Fixed afaik and see.

Hate to say it, but yeah. The whole header part is like about encoding and schemas - they are kinda the same to me.
Don't know XML, though so I'm looking at that as at HTML - DTD stuff, then maybe meta, then maybe stylesheet or schema. But still, it's just like making the text fit another standart, nothing exactly ground-breaking here to me.

Care to enlighten dark corners of my knowledge-base, maybe?

Also, i understand that getting into jsp-servlets without any xml knowledge isn't very good, but i didn't really consider it being anything serious.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

The latter specifies an entirely different version of the Servlet specification for the deployment descriptor. Apparently one that better matches the version of Tomcat you are using.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head first Servlets first example