How to display child page from specific parent page in homepage?

How can I change the homepage address when I deploy my application in production and hosting server?

  • I am working on a Spring web application. In my localmachine, the address I was using to see the home page is localhost:8080/ProjectName/mvc/template. But now in production if some one enter www [dot] myWebsite [dot] com I want them to take to the home page. How can I fix this? PS:  I deployed my war to the context path '/' in tomcat server. *Now, if I enter 111.111.111.111:8080/mvc/pageName, I could access the homepage. *Earlier, it use to be 111.111.111.111:8080/myprojectName/mvc/pageName. * But what I want is 111.111.111.111:8080 should be taken to homepage of my website. How to do this? This is how my web.xml looks <web-app version="2.2" id="WebApp_ID"> <!-- <display-name>Archetype Created Web Application</display-name> --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/mvc/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/WEB-INF/jsp/template.jsp</welcome-file> </welcome-file-list> </web-app> I already posted in SO as well http://stackoverflow.com/questions/26494363/how-can-i-change-the-homepage-address-when-i-deploy-my-application-in-production

  • Answer:

    Servlets have a concept of forwarding which transfer the control to another servlet URL, without changing the URL presented to the browser. In JSP, this can be used with the jsp:forward tag, which can be put in the welcome JSP. However, if the Spring MVC app relies on a relative paths, then the URL would need to be updated. The front-facing web server, like nginx, could do this. Putting a front-facing web server and hiding Tomcat is recommended. But if a front-facing web server is not used, then the redirect could be sent from the JSP, but using Java scriptlet code, which is not recommended. Another option is to write a servlet that handles the forward or redirect and mapping it to the webapp /.

Miguel Paraz at Quora Visit the source

Was this solution helpful to you?

Other answers

You can use nginx to redirect from `your_ip:8080/path/to/your/app` to `your_ip:80`. I found this link amongst other: http://www.mkyong.com/nginx/nginx-apache-tomcat-configuration-example/ that explains how to do it, and what is important is the nginx configuration.

Samuel Lê

Try keeping home page url outside WEB-INF folder. Check your directory structure.

Deepak Pandey

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.