随笔 - 5  文章 - 4  trackbacks - 0

留言簿

文章分类(2)

文章档案(7)

搜索

  •  

最新评论

servlet中
RequestDispatcher dispatcher = request.getRequestDispatcher(path);
dispatcher.include(request,response);

jsp中
<%@ include file="path"  %> (目前我没有测试出来这两者的区别,可能是使用eclipse的原因,一旦保存了后,将自动构建)
<jsp:include page="<%=path %>" >

这里面的 path 如果以 /起头,比如
/test/hello.jsp 就代表上下文的这个文件
./test/hello.jsp 当前文件下的/test/hello.jsp
../test/hello.jsp 当前文件的父亲的/test/hello.jsp
path同样可以是servlet里的mapping映射

servlet使用外部配置导入资源,需要在 web.xml进行配置
<servlet>
 <description></description>
 <display-name>HelloWorldServlet</display-name>
 <servlet-name>HelloWorldServlet</servlet-name>
 <servlet-class>testservlet.HelloWorldServlet</servlet-class>
 <init-param>
  <param-name>file</param-name>
  <param-value>/PrintLog</param-value>
 </init-param>
</servlet>
通过 String value = (String) getInitParameter("file"); 得到 /PrintLog

jsp使用外部配置导入资源
<%
java.util.ResourceBundle bundle = new java.util.ResourceBundle.getBundle("com.jspservletcookbook.include");
String segment = budle.getString("external-include");
%>
文件 include.properties 储存在 WEB-INF/classes/com/jspservletcookbook
文件 include.properties内容为:external-include=WEB-INF/jspf/header_tag.jsp

jsp导入上下文之外的内容
使用 c:import JSTL核心标记

posted on 2006-12-08 11:52 googlor 阅读(430) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: