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

Servlet Not working

Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Hello,
Sorry to trouble you all with a newbie Servlet question.

I am using JBoss. My servlet, HelloServlet, prints a simple Hello statement. I create a hello.war file with files

welcome.html
META-INF/Manifest.mf
WEB-INF/web.xml
WEB-INF/classes/HelloServlet.class


web.xml is as -

<?xml version="1.0"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>hello.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>welcome.html</welcome-file>
</welcome-file-list>
</web-app>

I place the hello.war in the jboss/server/default/deploy directory. JBoss starts up fine saying that the war file has been deployed.
In my browser, I type
http://localhost:8080/hello/welcome.html
This works fine.

However when I do
http://localhost:8080/hello/HelloServlet

I get
"javax.servlet.ServletException: Wrapper cannot find servlet class hello.HelloServlet or a class it depends on"
and so on.
I have been following the SAMS Teach yourself EJB book.

Any help would be MUCH appreciated.

DG
[ April 02, 2007: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

Compare these two items of info from what you posted:

WEB-INF/classes/HelloServlet.class

and

<servlet-class>hello.HelloServlet</servlet-class>

See what's wrong?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Hi,
Thanks for replying.

Comparing

WEB-INF/classes/HelloServlet.class
and
<servlet-class>hello.HelloServlet</servlet-class>

hello is the name of the war file in which the structure is
WEB-INF/classes/HelloServlet.class
so the servlet class refers to the fact that it is in the hello war file, with the standard directory packaging. At any rate HelloServlet.class is not in a 'package' but in default mode in the directory classes.

Next?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

Originally posted by Nupur Gupta:
<servlet-class>hello.HelloServlet</servlet-class>

hello is the name of the war file in which the structure is
WEB-INF/classes/HelloServlet.class so the servlet class refers to the fact that it is in the hello war file,


No, it doesn't. Your declaration states that the servlet is in a package named 'hello'. The war file name has nothing to do with anything.

Next?


Sarcasm will not win you much help in these forums.
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Hello,
I seriously was not being sarcastic. I am much too worried about the problem at hand. I really appreciate your help.
OK,so I rewrote my web.xml file as
<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>welcome.html</welcome-file>
</welcome-file-list>
</web-app>

I am afraid that http://localhost:8080/hello/HelloServlet still does not work, though
http://localhost:8080/hello/welcome.html does.
I would really appreciate any help.
Yellaiah Gopireddy
Greenhorn

Joined: Mar 24, 2007
Posts: 12
Hi Napur,
I hope with small change in your web.xml will solve your small

<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
/****upto this no problem*************/

You defined url pattern for your servlet like below
<url-pattern>/HelloServlet/*</url-pattern>

instead of this try to write like below
<url-pattern>/HelloServlet</url-pattern>

/*****below this also fine************/
</servlet-mapping>
<welcome-file-list>
<welcome-file>welcome.html</welcome-file>
</welcome-file-list>
</web-app>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Hi Yella,
Welcome to the Ranch, and thank you for your help.
Can you check the Naming Policy of the ranch and kindly change your name according to it ? Thanks in advance.
http://www.javaranch.com/name.jsp


[My Blog]
All roads lead to JavaRanch
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Hi Yella,
Thanks so much! But I am afraid it still does not work. Any help much appreciated.
DG
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

But I am afraid it still does not work.

What is the error ?
bala nannaka
Ranch Hand

Joined: Apr 02, 2007
Posts: 49
In Jboss server you contain tomcat server make it run in out process and deploy in webapps folder and try once
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Thanks so much.

Now I really can't figure out where to put the war file, and what URL to use to access it. Would REALLY appreciate some pointers.
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Also,
should my HelloServlet.java be in the package hello, or can it just be in default WEB-INF/classes/HelloServlet.class?
I am so confused
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

In your web.xml, the servlet is linked to hello.HelloServlet, so HelloServlet definitely has to be under the "hello" package, in the "classes" directory.
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
OK, I have tried some different things. I put HelloServlet.jar in the
package hello so it is now hello.HelloServlet. I do
http://localhost:8080/servlets/hello/HelloServlet
and get
The requested resource (/hello/HelloServlet) is not available.

Next, I use
jboss/catalina/webapps/servlets/helloapp and place
helloapp/META-INF
helloapp/WEB-INF/web.xml
helloapp/WEB-INF/classes/hello/HelloServlet.class
and do
http://localhost:8080/servlets/hello/HelloServlet
Now I get


No Context configured to process this request
server encountered an internal error (No Context configured to process
this request) that prevented it from fulfilling this request.


Oh dear, what Can I do?


Help MUCH appreciated. Probably will save my career.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16


You're telling that there is a servlet called HelloServlet, whose class file is in the "hello" package.
Accessing the URL "/HelloServlet" will redirect to this servlet.

So you're supposed to have : (replace "yourapp" by whatever application name you have)

webapps/yourapp/WEB-INF
webapps/yourapp/WEB-INF/web.xml
webapps/yourapp/WEB-INF/classes/hello/HelloServlet.class

Don't forget that in HelloServlet.java, you're supposed to have "package hello;" as the first line.

Then you can access it via
http://localhost:8080/yourapp/HelloServlet
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Thanks so much for your help. I followed it to the T, and I get

No Context configured to process this request

description The server encountered an internal error (No Context configured to process this request) that prevented it from fulfilling this request.


Further, if I do http://localhost:8080/helloapp/welcome.html, I get the same result.

Very confused.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

where is "helloapp" ? Under webapps ?
Do you have webapps/helloapp/WEB-INF ?
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Yes, I do
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Did you restart the container ?
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Yes, I restarted it. Let me give an overview of what I did again

I am using JBoss. My servlet, HelloServlet, prints a simple Hello
statement. I create a hello.war file with files


welcome.html
META-INF/Manifest.mf
WEB-INF/web.xml
WEB-INF/classes/hello/HelloServlet.class


web.xml is as -


<?xml version="1.0"?>


<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >


<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>hello.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>welcome.html</welcome-file>
</welcome-file-list>
</web-app>


I place the hello.war in the jboss/server/default/deploy directory.
JBoss starts up fine saying that the war file has been deployed.
In my browser, I type
http://localhost:8080/hello/welcome.html
This works fine.


However when I do
http://localhost:8080/hello/HelloServlet


I get
"Internal Server Error
The server encountered an internal error (Internal Server Error) that
prevented it from fulfilling this request"
..and so on


I have been following the SAMS Teach yourself EJB book.


Further, I have also tried putting my files in jboss/catalina/webapps
The structure is as


webapps/helloapp/welcome.html
webapps/helloapp/META-INF
webapps/helloapp/WEB-INF/web.xml
webapps/helloapp/WEB-INF/classes/hello/HelloServlet.class


At the browser, I do
http://localhost:8080/helloapp/HelloServlet and get


No Context configured to process this request
The server encountered an internal error (No Context configured to
process this request) that prevented it from fulfilling this request.


Please help. Thanks, DG
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Hi All,

I don't know how, but it seems to have all started working now.
I thank you all very very very much.
DG
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

"Yella G"

Sorry name still does not match the naming policy. Please review it and try again. This is your second warning.


My Blog: Down Home Country Coding with Scott Selikoff
Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
Hi nupur

you should use the following things and forgot all other things.

create a hello.war file with files


welcome.html
WEB-INF/web.xml
WEB-INF/classes/HelloServlet.class
it will automatically creates the manifest file don't worry about it.


web.xml is as -


<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>welcome.html</welcome-file>
</welcome-file-list>
</web-app>


place the hello.war in the jboss/server/default/deploy directory.
start the JBoss and type
http://localhost:8080/hello/HelloServlet


** not use the xml version tag in the web.xml file.

I hope all this will work fine. amar_deep_mca@yahoo.co.in


"A thinking mind never dies"
 
 
subject: Servlet Not working