如何从URL隐藏.xhtml扩展名 [英] How to hide .xhtml extension from URL

查看:123
本文介绍了如何从URL隐藏.xhtml扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSF 2.0中,如何隐藏URL的.xhtml扩展名?可以在web.xml中进行配置吗?

In JSF 2.0, how can I hide .xhtml extension from URL? Can this be configured in web.xml?

我只想将当前URL"http://localhost:8080/sms/faces/admin/account/process_monthly_fee.xhtml"更改为".../process_monthly_fee.jsf".

I just want to change current URL "http://localhost:8080/sms/faces/admin/account/process_monthly_fee.xhtml" to ".../process_monthly_fee.jsf".

web.xml中添加以下上下文参数不能解决我的问题,但是我的应用程序什么也不显示:

Adding following context parameter in to web.xml does not solve my problem but my application displays nothing:

<context-param>
   <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
   <param-value>*.jspx</param-value>
</context-param>

OR

<context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.jspx</param-value>
</context-param>

我的web.xml文件是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>School Management System</display-name>
  <welcome-file-list>
    <welcome-file>faces/index.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>

 <servlet>
    <servlet-name>upload</servlet-name>
    <servlet-class>com.sms.model.student.Upload</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>upload</servlet-name>
    <url-pattern>/Upload</url-pattern>
  </servlet-mapping> 
<servlet>
    <servlet-name>marks</servlet-name>
    <servlet-class>com.sms.student.service.Mark</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>marks</servlet-name>
    <url-pattern>/marks</url-pattern>
  </servlet-mapping>
  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error/error.xhtml</location>
  </error-page>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
<filter>
    <filter-name>Extensions Filter</filter-name>
    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Extensions Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>  
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>classic</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.enableControlSkinning</param-name>
<param-value>true</param-value>
</context-param>
</web-app>

推荐答案

如果只想更改扩展名,请遵循

If you want to just change the extension, follow the advice in the link provided by @Captain Giraffe.

要完全隐藏扩展名,可以使用 PrettyFaces OmniFaces .

To completely hide the extensions, you can use either PrettyFaces or OmniFaces.

OmniFaces展示柜 带有一个示例.

The OmniFaces showcase features an example.

编辑:我想@Captain Giraffe提供的链接解决了一个不同的问题-如何使扩展名不同于.xhtml的文件被JSF接收.

EDIT: I suppose the link provided by @Captain Giraffe solved a different issue - how to have files with a different extension then .xhtml to get picked up by JSF.

如果要在URL末尾更改扩展名,可以将其添加到web.xml:

If you want to change the extension at the end of your URL, you can add this to your web.xml:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.foo</url-pattern>
</servlet-mapping>

从现在开始,您的页面将以/YourApplicationRoot/pagename.foo

From now on, your pages will be accessible as /YourApplicationRoot/pagename.foo

这篇关于如何从URL隐藏.xhtml扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆