0

Alternative title: Unable to find [main.SearchServlet], mapping my servlet in Tomcat whilst using annotations

I'm trying to migrate my web application from java netbeans glassfish jdk 1.8 to eclipse tomcat jdk 1.7.

I keep getting a 405 then 404 error when I try to perform my POST by pressing a button on my loaded index jsp.

javax.naming.NameNotFoundException: Name [main.SearchServlet/annj] is not bound in this Context. Unable to find [main.SearchServlet].

I thought that setting a <context root>/</context root> in web.xml would fix this. It did move my loading page from localhost/animelist/index and localhost/animelist down one level to localhost/ and localhost/animelist however it did not fix my error.

As it stands, my project does not run at http://localhost:8080/ or http://localhost:8080/index.jsp . It DOES run at http://localhost:8080/animelist1/ and http://localhost:8080/animelist1/index.jsp

The project works fine in my netbeans setup so my question is what do i need to do for my servlets to be mapped properly in tomcat?

Someone said that " Likely the only problem you have is that the application deployment in your secondary Eclipse isn't working properly yet. As in: the servlet class file is not deployed to the server at all." I'm not sure how to go about fixing this (or googling for it).

I have my classes instanced with

@EJB
private AnnJAXB annj;

and servlet with

@WebServlet(name = "SearchServlet", urlPatterns = { "/search" })

and like i said it all works in netbeans setup.

so do i have to do something with tomcat config or application properties, since deployment should be done automatically? why isn't mainClass.SearchServlet being found?

thankyou for reading. i am near the end i feel . it has been 15 hours trying to deploy this to a host and it is exhausting.

Percy
  • 113
  • 1
  • 2
  • 11
  • 1
    Duplicate of : http://stackoverflow.com/questions/7276989/howto-set-the-context-path-of-a-web-application-in-tomcat-7-0 – Dan Apr 20 '15 at 14:39
  • I tested changing my root with / in server.xml however I still got the Unable to find [mainClass.SearchServlet] error. I also tried altering the urlPattern of searchservlet and the URL in my jquery. Is there something else that might effect SearchServlet not being located, such as a setup/build setting? Also this doesn't explain why my web app appears at /localhost/animelist/ in Eclipse but appears in localhost/ in my netbeans setup . Whats causing the differentiation? – Percy Apr 20 '15 at 14:43
  • You shouldn't be trying to deploy at root. Better to use the context root, in my opinion. You're wasting time fighting it. – duffymo Apr 20 '15 at 14:46
  • I just thought that identifying why its deploying where it is might help me fix it. I've tried both ways and it just can't find the servlet. I have not added anything to xml files to identify the servlet mapping because I am using those annotations. maybe i should try the "old" method and use an xml mapping thing? – Percy Apr 20 '15 at 14:54

0 Answers0