如果您使用dwr 是否为配置了创建器后还要在用到的jsp文件头中写包含JavaScript文件烦恼呢
本文分享一个技巧,把下面代码加入jsp的头部,以后再用不着一个个写了,直接用就行
<%@ page pageEncoding="utf-8"%>
<%@page import="org.directwebremoting.impl.*,java.util.*"%>
<%@page import="org.directwebremoting.Container"%>
<%@page import="org.directwebremoting.extend.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("base",basePath);
List<Container> clist = (List<Container>)application.getAttribute(ContainerUtil.ATTRIBUTE_CONTAINER_LIST);
Container container = (Container)clist.iterator().next();
CreatorManager creators = (CreatorManager)container.getBean("org.directwebremoting.extend.CreatorManager");
//Remoter remoter = (Remoter ) container.getBean("org.directwebremoting.extend.Remoter");
String dwrinterface = (String)container.getBean("interfaceHandlerUrl");
String contextpath = request.getContextPath();
String dwrjsprefix = contextpath+"/dwr"+dwrinterface;
%>
<!--Dwr js included -->
<%
for(Object name: creators.getCreatorNames()){
String cname = (String)name;
String js = creators.getCreator(cname).getJavascript();
%>
<script language="javascript" type="text/javascript"
src="<%=dwrjsprefix+js+".js"%>"></script>
<%
out.println("\n");
//输出engine.js 和util.js
}
%>