java 开源cms opencms的使用,如何去掉两个/opemcms路径的方法

哈哈。。。经过本人测试成功:

 

买空间的朋友,因为无法配置apache配置,所以得用urlRewrite.jar来url重写的方式,去掉/opencms

我的环境是:JDK6.0 ,TOMCAT 6

 

第一步:去掉第一个/opencms

 

把下载来的opencms.jar改成ROOT.jar包,放在tomcat/webapps下,运行安装。。这样第一个/opencms 自然就去掉了,不用什么力气,也不用配置什么别的,如果您不想把opencms放了ROOT目录,也可以像其它人一样,配置虚拟目录来设置,在baidu搜索一下就有很多方法去掉第一下opencms

 

 

第二步:去掉第二个/opencms  也是我们要处理的关键部分。

现在的任务是要去掉第二个,opencms文档中,是安装apache,并使用apache的urlrewrite模块来对项目的URL进行重定向, 现在我们要使用 urlrewrite来完成这任务,如果不知道urlrewrite的朋友,可以到http://tuckey.org/urlrewrite/下载。

 下载完以后,把urlrewrite.zip里面的/WEB-INF/lib/urlrewrite.jar放到我们项目的/WEB-INF/lib/urlrewrite.jar里。

然后,在/WEB-INF/目录下新建一个urlrewrite.xml文件,里面的内容为:

 

注意一定要下载:urlrewrite-3.1.0.jar 版本,因为我之前使用的其它版本,没有成功。后台页面乱码。

 

附件一:urlrewrite.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN"
"http://tuckey.org/res/dtds/urlrewrite3.1.dtd">

<!--

Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/

-->
<urlrewrite>
<rule>
<from>^/(.*)</from>
<to>/opencms/$1</to></rule>

 

<rule>
<from>^/opencms/webdav/(.*)</from>
<to>/webdav/$1</to></rule>

 

[备注:这个是为了后面学习在eclipse导入webdav时用的,只有匹配了这种的规则,才可以通过http://localhost:8080/webdav 访问,否则无法访问资源。此备注,在copy时要删除。]

 

<rule>
<from>^/opencms/opencms/(.*)</from>
<to>/ztend/$1</to></rule>

<rule>
<from>^/opencms/resources/(.*)</from>
<to>/resources/$1</to></rule>

<rule>
<from>^/opencms/export/(.*)</from>
<to>/export/$1</to></rule>
</urlrewrite> 

 

创建好以后,打开/WEB-INF/web.xml文件,找到以下代码:

    <listener>
        <listener-class>org.opencms.main.OpenCmsListener</listener-class>
    </listener>

 

然后在其后面加上:

    <filter>
       <filter-name>UrlRewriteFilter</filter-name>
       <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>

 

附本人:web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 version="2.4">

    <display-name>OpenCms</display-name>
   
    <description>
        OpenCms, the Open Source Content Management System.
        (c) 2010 Alkacon Software GmbH with contributions from the OpenCms community.
        For more details about OpenCms, please see http://www.opencms.org/.
        For more details about Alkacon Software GmbH, please see http://www.alkacon.com/.   
    </description>

    <!--
        Changing the servlet name from "opencms" to something else requires 2 changes in this file.       
        For example, to change the servlet name to "mycms" you must:
       
        1. Change the <context-param> called "OpenCmsServlet" from "/opencms/*" to "/mycms/*"
        2. Change the <servlet-mapping> for "OpenCmsServlet" from "/opencms/*" to "/mycms/*"
    -->
   
    <!--
     Changing the errorhandler servlet name from "opencms-errorhandler" to something
  else requires 3 changes in this file.
  For example, to change the servlet name to "mycms-errorhandler" you must:

  1. Change the <servlet-mapping> for "OpenCmsServletErrorHandler" from
     "/opencms-errorhandler/*" to "/mycms-errorhandler/*"
  2. Change the <error-page> setting for the 404 error from
     "/opencms-errorhandler/handle404" to "/mycms-errorhandler/handle404"
  3. Change the <error-page> setting for the 500 error from
        "/opencms-errorhandler/system/handler/handle500.html" to
        "/mycms-errorhandler/system/handler/handle500.html"
    -->

    <context-param>
        <param-name>OpenCmsServlet</param-name>
        <param-value>/opencms/*</param-value>
    </context-param>
   
    <context-param>
        <param-name>DefaultWebApplication</param-name>
        <param-value>ROOT</param-value>
    </context-param>   
   
 <!--
     Uncomment this parameter in case you change the web application context using an application server
     specific deployment descriptor. E.g. in Jboss, you could use the jboss-web.xml file to deploy opencms under the
     context 'myopencms' but still keep the files in the folder 'opencms.war'

    <context-param>
        <param-name>WebApplicationContext</param-name>
        <param-value>myopencms</param-value>
    </context-param>
    -->

    <listener>
        <listener-class>org.opencms.main.OpenCmsListener</listener-class>
    </listener>
   
     <filter>
   <filter-name>UrlRewriteFilter</filter-name>
   <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
   </filter>
   <filter-mapping>
   <filter-name>UrlRewriteFilter</filter-name>
   <url-pattern>/*</url-pattern>
   </filter-mapping>

       
    <servlet>
        <description>
            The main servlet that handles all requests to the OpenCms VFS. 
        </description>
        <servlet-name>OpenCmsServlet</servlet-name>
        <servlet-class>org.opencms.main.OpenCmsServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
   
    <servlet>
        <description>
            The error handling servlet, also serves as trigger for static export requests. 
        </description>
        <servlet-name>OpenCmsServletErrorHandler</servlet-name>
        <servlet-class>org.opencms.main.OpenCmsServletErrorHandler</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>   

    <servlet>
        <description>
            Creates an access to OpenCms through WebDAV.
        </description>
        <servlet-name>OpenCmsWebDavServlet</servlet-name>
        <servlet-class>org.opencms.webdav.CmsWebdavServlet</servlet-class>
        <init-param>
          <param-name>listings</param-name>
          <param-value>true</param-value>
        </init-param>
        <init-param>
          <param-name>readonly</param-name>
          <param-value>false</param-value>
        </init-param>
        <init-param>
          <param-name>repository</param-name>
          <param-value>standard</param-value>
        </init-param>
    </servlet>
   
    <servlet-mapping>
        <servlet-name>OpenCmsServlet</servlet-name>
        <url-pattern>/opencms/*</url-pattern>
    </servlet-mapping>
   
    <servlet-mapping>
        <servlet-name>OpenCmsServletErrorHandler</servlet-name>
        <url-pattern>/opencms-errorhandler/*</url-pattern>
    </servlet-mapping>
   
    <servlet-mapping>
      <servlet-name>OpenCmsWebDavServlet</servlet-name>
      <url-pattern>/webdav/*</url-pattern>
    </servlet-mapping>
   
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index_export.html</welcome-file>
    </welcome-file-list>
   
    <error-page>
        <error-code>404</error-code>
        <location>/opencms-errorhandler/handle404</location>
    </error-page>

 <error-page>
        <error-code>500</error-code>
        <location>/opencms-errorhandler/system/handler/handle500.html</location>
    </error-page>

 <jsp-config>
     <taglib>
         <taglib-uri>http://www.opencms.org/taglib/cms</taglib-uri>
         <taglib-location>/WEB-INF/opencms.tld</taglib-location>
     </taglib>
 </jsp-config>

</web-app>

 

 

第三步:

至此,已完成了第二个opencms的去除,但如果此时运行项目的话,项目中的URL地址还是会有/opencms/,所以我们要把URL中的这个路径去掉。

 

 

打开/WEB-INF/config/opencms-importexport.xml

找到代码:<vfs-prefix>${CONTEXT_NAME}${SERVLET_NAME}</vfs-prefix>

将其修改为: <vfs-prefix>${CONTEXT_NAME}</vfs-prefix>

现在,第二个opencms的去除已成功。

 

 

我的小站:http://www.lsoba.com

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值