BugsEverywhere
BugsEverywhere

Reputation: 9

spring MVC web app works perfectly on Windows but not on Linux


Hi:

I am a starter on spring MVC web development. Recently I wrote the first web app using Spring MVC framework, but without any .xml configuration (pure Java annotation configure), and my web.xml is look like the figure here. And it's quite weird because the web app works fine on Windows with Tomcat but not on Linux.

To be specific, when it runs in tomcat on Linux(Ubuntu or Redhat), I can see the welcome page of tomcat by typing ip:port on other machine, instead of the first page of index.jsp in my web project. If I request other url in the web project, it responses with 404 error.

So I think, obviously, the web app has not been loaded into tomcat (apologize for the unprofessional description) at all. The way I inject the project into tomcat is the same as on Windows, which is copying the war package into webapps folder. I can even see the unzipped folder after start tomcat, which means that the little tiger did recognize it, right? And the issues of environment variables (jdk or tomcat) are not the problem because tomcat did start.

The reason, I suppose, is that, I have nothing in my web.xml file since I use pure Java annotation method configuration, causing that tomcat didn't know which servlet to load~~(pure guess XD). Or is there anything specific on Linux which need to be configured for this? I am quite confused.

The repository of this project on gihub is here.

Please help me if you have any idea about this issue.


Thank you!

Upvotes: 0

Views: 399

Answers (1)

cmb28
cmb28

Reputation: 421

try initializing the servlet like this in web.xml,

<servlet>
    <servlet-name>Name</servlet-name>
    <servlet-class>ServletClass</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>

then map that servlet to your JSP

<servlet-mapping>
    <servlet-name>Name</servlet-name>
    <url-pattern>/samplePage</url-pattern>
  </servlet-mapping>

then you can find the page at,

http://localhost:8080/ProjectName/samplePage.jsp

Upvotes: 0

Related Questions