Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resource not found error in JAX-RS web service

 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have to create web services for my project. I am new to advance java and creating Java web services for the first time. This is my servlet-



I want to call the service named "smooth" which prints content on console.

This is the web.xml file-


The url i'm using is-
http://localhost:8080/ServletExporer/HelloWorldServlet/smooth

But it gives error 404-Resource not found sometimes and sometimes it throws ClassNotFoundException.

Please tell me what wrong i'm doing.

Thanks in advance.
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the environment/setup etc... you are using this? You might need to explain more details about other aspects involved here.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <servlet-class> attribute needs to contain the fully qualified class name of the servlet - that includes the package information, which is currently missing.

I wouldn't mix a WebServlet annotation with a servlet declaration in web.xml - use one or the other, but not both.

Lastly, I don't think you can mix a servlet with a JAX-RS service in the way you do (nor should you, even if it works). Have you tried creating a JAX-RS service without making it a servlet?
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying

Vijitha Kumara wrote:What is the environment/setup etc... you are using this? You might need to explain more details about other aspects involved here.

Please tell what details are required? I am using Tomcat as server.
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:The <servlet-class> attribute needs to contain the fully qualified class name of the servlet - that includes the package information, which is currently missing.

I wouldn't mix a WebServlet annotation with a servlet declaration in web.xml - use one or the other, but not both.

Lastly, I don't think you can mix a servlet with a JAX-RS service in the way you do (nor should you, even if it works). Have you tried creating a JAX-RS service without making it a servlet?

I tried writing fully qualified class name of the servlet but the url http://localhost:8080/ServletExporer/HelloWorldServlet/smooth calls the method doGet() but I want to call my web service method smooth(). How to do that?


Thanks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doGet is a servlet thing. That's why you should not make your JAX-RS handler a servlet.
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I got it. Tried selecting option web services in ecllipse and now its working fine
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic