remove application name from URL

谁说胖子不能爱 提交于 2019-11-29 23:19:08

问题


my site uses JSF and the url appears to be, http://mysitename.com/wompower6/faces/home.xhtml

I am using prettyfaces, so if I use the following in pretty-config.xml, i can change the name to http://mysitename.com/wompower6/home

<url-mapping id="home">
    <pattern value="/home" />
    <view-id value="/faces/home.xhtml" />
</url-mapping>

my questions are

  1. how can i remove the application name wompower6 , so that the url becomes mysitename.com/home ?

  2. in my web.xml, i have <welcome-file>home.xhtml</welcome-file>, but this does not seem to work. When i type, mysitename.com, it does not get mapped to home.xhtml. any clue here?


回答1:


how can i remove the application name wompower6 , so that the url becomes mysitename.com/home?

This is a webapp <Context> setting and configuration is dependent on the servletcontainer used. If you're for example using Tomcat, then there are basically 2 options to make your webapp the root webapp.

  1. Rename the WAR file to ROOT.war and Tomcat will by default deploy it on context root.

  2. Set path attribute of <Context> element in Webapp/META-INF/context.xml (or Tomcat/conf/server.xml, depending where you'd like to define it) to an empty String. E.g.

    <Context path="" ...>
    

Other containers support similar constructs. Consult their documentation for detail. If you're using an IDE like Eclipse, then you can also set it in the Web Project Settings property of the project properties (rightclick project and choose Properties). Set the Context root value to just /.


in my web.xml, i have home.xhtml, but this does not seem to work. When i type, mysitename.com, it does not get mapped to home.xhtml. any clue here?

I assume that you're talking about the <welcome-file> setting. This has to point to a physically existing file, not to a virtual URL, such as /faces/*. There are basically two ways to overcome this:

  1. Provide a physically existing /faces/home.xhtml file (it can even be left empty).

  2. Replace the ugly /faces/* URL pattern of the FacesServlet mapping in web.xml by *.xhtml so that it will just kick in on every request for a XHTML file.

    <url-pattern>*.xhtml</url-pattern>
    

    This way you don't need to fiddle with /faces/* URL patterns.



来源:https://stackoverflow.com/questions/6546951/remove-application-name-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!