I've a Spring MVC application successfully deployed and running on Tomcat. Now, I'm trying to move it to glassfish, simply because, I want to set-up JNDI data source from admin console.
Now, when I deploy the war file in glassfish, and launch the application, it is successfully launching the welcome file that is setup in web.xml
:
<welcome-file-list>
<welcome-file>home</welcome-file>
</welcome-file-list>
The link on the browser at this time is:
http://localhost:8080/ContextRoot
The welcome page has some link like these:
<a href="orders">Manage Orders</a>
And I've a controller mapped at that url:
@Controller
@RequestMapping("/orders")
public class OrderItemController {
@RequestMapping(method = RequestMethod.GET)
public String displayTables(Model model,
@RequestParam(value="message", required = false) String message) {
occupiedTables = tableService.getOccupiedTables();
model.addAttribute("message", message);
model.addAttribute("occupiedTables", occupiedTables);
return "orderItem";
}
}
But, when I click on that link (orders
) on that page, the context root is gone and what I'm left with is:
http://localhost:8080/orders
So, since the context root is no longer being shown, the application itself cannot be found. And I'm getting a 404 error.
My question is, do I need to do some changes while moving an application from Tomcat to Glassfish? After searching through the internet, I added a glassfish-web.xml
, in parallel with the web.xml
in my application with the following content:
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<context-root>/ContextRoot</context-root>
</glassfish-web-app>
But it's not helping. I can also see the context root being listed as a part of application in the glassfish admin console.
What is the problem here? Am I missing something else.
Update:
When I set the Default Web Module in glassfish admin console:
'Configuration' -> 'Virtual Servers' -> 'server' -> 'Default Web Module'
Then everything's working fine. The context root is not needed at all. So, the application welcome file is accessible at:
http://localhost:8080
and clicking the orders
link will take me to:
http://localhost:8080/orders
which is working fine, as the application is default, and context root is not needed now.
Now, isn't there any to do this without making the application default, and giving the context root explicitly?