在SHTML中通过SSI指令实现文件动态包含

来源:互联网 发布:java工作流引擎 开源 编辑:程序博客网 时间:2024/05/16 05:28

文章地址: http://blog.csdn.net/5iasp/article/details/12992769

作者: javaboy2012
Email:yanek@163.com
qq:    1046011462

 

在SHTML中通过SSI指令实现文件动态包含

代码如下:

测试代码:

假设文件为index.shtml 内容如下:

<!--#if expr="$QUERY_STRING='id=1'" --> <!--#include virtual="/test/1.inc" --><!--#endif --> <!--#if expr="$QUERY_STRING='id=2'" --> <!--#include virtual="/test/2.inc" --><!--#endif --> <!--#if expr="$QUERY_STRING=''" --> <!--#include virtual="/test/3.inc" --><!--#endif --> 


 

有如下三个被包含的文件。

http://www.myweb.com/test/1.inc
http://www.myweb.com/test/2.inc
http://www.myweb.com/test/3.inc

index.shtml的发布路径:

http://www.myweb.com/index.shtml

http://www.myweb.com/test/index.shtml?id=2  则执行后显示包含2.inc的内容
http://www.myweb.com/test/index.shtml?id=1  则执行后显示包含1.inc的内容
http://www.myweb.com/test/index.shtml       则执行后显示包含3.inc的内容


通过如上处理则可以实现实现在服务器端实现动态包含。

在apache服务器下测试通过。

 

参考资料: http://apache.jz123.cn/howto/ssi.html

ssi参考文档 : http://download.csdn.net/detail/5iasp/6445779