aspose file tools*
The moose likes Servlets and the fly likes 1st servlet example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "1st servlet example" Watch "1st servlet example" New topic
Author

1st servlet example

srikanth sri
Greenhorn

Joined: Feb 21, 2010
Posts: 20
i have tomcat 6.0
i have written the 1st servlet example from HFSJ but not working.

error requested resource not available.

enabled the invoker serlet but no use.

please help me out!

thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

You have not given anywhere enough details. Please read TellTheDetails.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
srikanth sri
Greenhorn

Joined: Feb 21, 2010
Posts: 20
here is my problem

my directory structure is C:\apache-tomcat-6.0.24\webapps\ch1\WEB-INF\classes in that i copied the ch1servlet.class file

and in C:\apache-tomcat-6.0.24\webapps\ch1\WEB-INF directory i wrote my web.xml

this is a simple servlet and i could open my tomcat home page and when i deploy it like

http://localhost:8080/ch1/serv1 i got error like The requested resource () is not available

can you please tell me the solution.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

Here's a tip: if you make it hard for people to help you, they'll just move on.

Don't tell us that you've set up the deployment descriptor (web.xml), show it! (And be sure to use code tags!)

Meanwhile some things to check: be sure that your servlet is in a package other than the default, and that the package hierarchy is reflected properly in WEB-INF/classes.

And disable the invoker -- you don't want to use it.
srikanth sri
Greenhorn

Joined: Feb 21, 2010
Posts: 20
sorry to pain you but this was my first post in this site and just joined now

and beginner in java
srikanth sri
Greenhorn

Joined: Feb 21, 2010
Posts: 20
i wrote the first servlet example from Head First Servlets ans JSP's so there are packages yet in my program.

just one servlet which is compiled and i copied the ".class" file and kept in classes folder and one web.xml file in WEB-INF folder.

i have recorrected the invoker servlet in web.xml file
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

I repeat:
Be sure that your servlet is in a package other than the default

Do you want it to work or not?
srikanth sri
Greenhorn

Joined: Feb 21, 2010
Posts: 20
here is my java code

and the web.xml is

and directory structure is
C:\apache-tomcat-6.0.24\webapps\ch1\WEB-INF\classes in this there is a ch1servlet.class file

and in C:\apache-tomcat-6.0.24\webapps\ch1\WEB-INF is my web.xml file

so i typed the http://localhost:8080/ch1/serv1

the error is ---requested resource cannot be found

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

This is the last time that I'm going to try:
Be sure that your servlet is in a package other than the default
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
I think the OP doesn't understand what Java packages are.

Srikanth: What Bear is referring to is Java packages. Your servlet source file (.java) needs to include a line at the top like the following:


This places your class in the com.mypackage package. Of course, you can select any package you want. I've used com.mypackage throughout this post. After compiling the source to a .class file, the .class file needs to be placed in the WEB-INF/classes/com/mypackage directory - see how the directory structure under WEB-INF/classes matches the package name described in the source file?

Assuming the above package name, the fully-qualified name of your servlet class will then be com.mypackage.ch1servlet. This needs to be correctly set in the web.xml file (as the <class-name> element).

Next, you need to use code tags anytime you include information that should be in mono-spaced font, like code listings, XML file listing, error stack traces, etc. Go back to your existing posts and click on the edit button, then add these. You can highlight the text you want to place in code tags then click the Code button. Then you will see what it looks like.

Good luck.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
I didn't notice before making my posting that the topic is marked as resolved. Did the OP resolve the issue. Can you please share your solution with the rest of the class?
srikanth sri
Greenhorn

Joined: Feb 21, 2010
Posts: 20
i have changed everything as you said but no difference in execution
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
srikanth sri wrote:i have changed everything as you said but no difference in execution


I think you missed something. In what directory under WEB-INF did you place your class file?

Also, what is the name of your doGet method in your Java source file? Note: case matters.


 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 1st servlet example