1
votes

I have a webapp with Maven which uses Tomcat plugin for the server. The app gets compiled to .war which, when extracted, seems to contain all classes (incl. servlets) in WEB-INF/classes folder.

When the url http://localhost:8080/com.galya.crm gets hit, index.html (which is a SPA app) gets loaded normally redirecting to http://localhost:8080/com.galya.crm/#!/login/msg/notlogged

I have 4 servlets annotated in a similar manner:

@WebServlet("/restapi/login")
public class LoginController extends HttpServlet {

The problem comes when the SPA app tries to authenticate using the login servlet (shown above). I expect it to be here: http://localhost:8080/com.galya.crm/restapi/login , but I get 404 error.

Below I attached the Tomcat plugin folder that is automatically created. Work directory is empty and I'm not sure if it's OK.

enter image description here

Initially the webapp/WEB-INF/web.xml was auto generated and contained the following:

<!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>
<display-name>Archetype Created Web Application</display-name>
</web-app>

I also tried to change it to accept WebServlet annotations, but didn't work also:

<!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 xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">
</web-app>

P.S. The app was working on another server some time ago, so the problem should be in the server configurations, not in the code itself.

1
I just saw that that Tomcat server uses its configuration from \target\tomcat\conf\web.xml where version is "2.5". Seems like this should be the problem, but pasting the snippet for 3.0 from above doesn't work... - Galya
OK, it seems that I did a terribly stupid mistake. I run the command tomcat:run which started some other sever configured with Idea, not the plugin. Now when I use the command tomcat7:run and using the version 3 configs, the servlets work. But the index.html now gives 404 error even when listed in welcome-file-list - Galya

1 Answers

0
votes

Surely the cause is that the deployment descriptor must be declared to be of version 3.0. Your web.xml is still 2.3.

Remove the DOCTYPE declaration and leave the root node just as you already did:

<web-app 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

Tested myself, and it worked.