0

I am developing jsf project. I want to remove project name in URL . I want http://localhost:8080 instead of http://localhost:8080/simpleJSF1/. The problem is in my java code i have to write project name to redirect to another page Like this.

FacesContext.getCurrentInstance().getExternalContext().redirect("/simpleJSF1/login.xhtml");

If i somehow able to to remove project name from url then i can write like this FacesContext.getCurrentInstance().getExternalContext().redirect("/login.xhtml");

instead of FacesContext.getCurrentInstance().getExternalContext().redirect("/simpleJSF1/login.xhtml");

Any help would be appreciated. Thanks in advance.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Devender Kumar
  • 515
  • 1
  • 5
  • 12
  • Wait, you just want to split a string based on a delmiter? – user1231232141214124 Dec 15 '15 at 17:13
  • No, I want when i run project and enter http://localhost:8080 my project should run. Now to run the project i need to enter project name after port number like this http://localhost:8080/simpleJSF1/. where simpleJSF1 is my project name. – Devender Kumar Dec 15 '15 at 17:23

1 Answers1

1

You could simply use your context as provided by ExternalContext - that way it's neither hard coded nor limited to ROOT-context.

FacesContext ctx= FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext) ctx.getExternalContext().getContext();
ctx.getExternalContext().redirect(
    servletContext.getContextPath() +"/login.xhtml");
Jan
  • 13,738
  • 3
  • 30
  • 55
  • Thanks a ton that solve problem. But is there any way to remove project name from URL like http://localhost:8080 to open project directly. I do not want to see project name in URL . – Devender Kumar Dec 15 '15 at 17:31
  • 1
    Deploy it as root webapp (in tomcat ROOT.war ) – Jan Dec 15 '15 at 17:34