0

As i mentioned in the title i deployed my java web project to tomcat path /Test2 (before it was deployed to tomcat ROOT and all was working perfectly) and all my webServlets stop working.Here's my servlet settings;

@WebServlet(
    name = "SessionLab",
    urlPatterns = {"/search","/newcontact","/gosearch","/gocontact","/index"},
    initParams = {
            @WebInitParam(name = "filename", value = "addressBook.txt")
    })

and there was this function to find the relevant urlpath and forward the request

 if(request.getRequestURI().equals("/search")) {
        readAddressbook(request, response);
    }
    else if(request.getRequestURI().equals("/newcontact")) {
        addnewContact(request, response);
    }
     .........<so on>

Everything stopped working after i deploy them to folder path rather than ROOT of tomcat9. I even changed the web.xml for url mapping as follows;

<servlet>
    <servlet-name>SessionLab</servlet-name>
    <servlet-class>test.AddressBookServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>SessionLab</servlet-name>
    <url-pattern>/Test2/*</url-pattern>
</servlet-mapping>

Still its not working, i getting 404 error. how to fix this?

namila007
  • 1,044
  • 9
  • 26
  • `/Test2/*` you should not do so. In `web.xml` you must specify URLs relative to the context path (which is `/Test2` in your case). – Roman Puchkovskiy Feb 26 '18 at 19:04
  • @RomanPuchkovskiy okay i changed url pattern to `/Test2/` and changed `@webservlet urls to "Test2/gosearch".. ` still not working – namila007 Feb 26 '18 at 19:07
  • You don' tneed to change @WebServlet urls either. They need to stay `/gosearch` and so on. You application does not need to know anything about that `/Test2` prefix, everything is done by a container (Tomcat) when you deploy under context `/Test2` there. – Roman Puchkovskiy Feb 27 '18 at 05:09

1 Answers1

0

Try changing the url pattern to /*, and hit the page.

Midhun
  • 146
  • 1
  • 4