Saturday, August 2, 2014

Making a Web Application as default in Tomcat

When we do not specify any context path in the url, it goes to the default page of Tomcat. If you are looking for a way to change the default to go to your application, then there are couple of ways to achieve that. The default page of the server is basically decided by the ROOT application (Note the caps and better note it). So the ways to make your app as default are as follows. We will assume that your application is sitting at context or doc root at myApp.
  • Rename your war file and ROOT.war. This will explode your application in a ROOT folder and Tomcat will take your application as the default application. You can also do the same things by replacing the stuff inside the ROOT with your application stuff.
  • The second way to change the redirection in the default index.jsp file sitting inside ROOT directory. For that first rename your index.html or index.jsp. Now create a new index.jsp and put the following
<%@ page session="false" %>
<%@ page import="javax.servlet.http.*" %>
<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", "https://<url of server>/myApp"); %>
Now the app will be redirected to your app. I have tried this way and it works for me.
  • The third way is to change the Host section in conf/server.xml. You might want to stop the automatic deployment and deploy the application manually by putting a line for each hosted app. I tried this but did not worked for me at the moment.

No comments:

Post a Comment