This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Create servlet in web.xml  RSS feed

 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

After (struggled) successfully installing Tomcat, I started to re create BeeServlet (code is given) from the assignment. I am not familiar with XML so i did some research online. I created an web.xml file and put it under
C:\tomcat\apache-tomcat-8.0.12\webapps\bee\WEB-INF

The web.xml i created has the following code:




However, when I ran tomcat and directed my browser to

http://localhost:8080/bee/BeeServlet

I received the following message..

HTTP Status 404 - /bee/BeeServlet
message /bee/BeeServlet
description The requested resource is not available.

I have the compiled BeeServlet class on
C:\tomcat\apache-tomcat-8.0.12\webapps\bee\WEB-INF\classess

Is there anything wrong with my web.xml? Do I need anything else?

Thank you in advance.
Gary
 
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an entry in the ServletsFaq that details the steps to take.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear for the reply.

I looked through Servlets Faq. Under the ServletNotRunning404 which is the error I am getting, it looks like I covered what can go wrong.
- The .class file is under WEB-INF/classes.
- I do have a servlet mapping on web.xml.
- The url path http://localhost:8080/bee/BeeServlet is the same as URL pattern /bee/BeeServlet

I know this is probably a stupid mistake. Can you point out any obvious mistake I am running into?

Thank you for the help.
Gary
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you put the class in a package like the list says?
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The BeeServlet.class is under bee\WEB-INF\classes.

The url is http://localhost:8080/bee/BeeServlet so i have url-pattern as /bee/BeeServlet

I also looked at this link for more information. http://www.tutorialspoint.com/servlets/servlets-packaging.htm

I can view the examples that is included on tomcat. BeeServlet.java is copied from the example and compiled then moved .class to bee\WEB-INF\classes folder

Where is the error?

Gary

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Did you put the class in a package like the list says?

 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I packaged the class in

C:\tomcat\apache-tomcat-8.0.12\webapps\bee\WEB-INF\classes
and web.xml is located in C:\tomcat\apache-tomcat-8.0.12\webapps\bee\WEB-INF

Before that though, I have put the .java file under C:\Java\development\bee\src and compiled it to C:\Java\development\bee\build\classes
Once compiled, I copied BeeServlet.class into C:\tomcat\apache-tomcat-8.0.12\webapps\bee\WEB-INF\classes

Is that what you meant?

Thank you for being patient

Gary
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gary Ba wrote:Before that though, I have put the .java file under C:\Java\development\bee\src and compiled it to C:\Java\development\bee\build\classes
Once compiled, I copied BeeServlet.class into C:\tomcat\apache-tomcat-8.0.12\webapps\bee\WEB-INF\classes


Then you have not packaged the class. The class must be in a package other than the default.

Sounds like that may be a new concept to you: Java Package Tutorial
 
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, this may be the fault of the instructions. While the progression of the assignments do teach that servlet classes (like all classes) should be put into packages, this concept isn't introduced until a bit later in the process. The Now servlet certainly used to be deployable in Tomcat without needing to be in a package. I'll have to upgrade my Tomcat installation and check if that's no longer the case. If so, I'll have to rearrange the lesson plan a bit. Give me a day or so to figure this out.
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks to me like putting the Servlet class into a package is only necessary if you create the mapping via the web.xml file. This sounds vaguely familiar, and I'll try to track that down in the Servlet Spec. In this case, you don't need a web.xml file at all though, because the servlet uses a WebServlet annotation.



If you delete the web.xml, I think everything will work for you. You may need to restart Tomcat, or wait 20 seconds or so to give it a chance to redeploy. You will be learning more about web.xml files and packages as you proceed through the servlet assignments.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Greg! I deleted the web.xml and the BeeServlet worked.

Bear, I skimmed through the tutorial and I will read more into it once I have more time. Its a little intimidating to get question from your status.

Man....for now, it is working so I can move on to the next part of the instructions whew...

Gary
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66783
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gary Ba wrote:
Bear, I skimmed through the tutorial and I will read more into it once I have more time. Its a little intimidating to get question from your status.


No need. I was a beginner once too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!