在写JSP页面的时候,我们经常要能过一个相当于对话框的页面里面选择我需要的一些选项,如发邮件的用户名,企业通讯录中的部门,等等其它信息。
先做一个查询页面
程序段中的变只要不是在这里定义的,那一定是通过程序从数据库里取出来的,(对别人有用的,其实只有最后一句话,只是我经常要用,所以把所有程序段都copy下来了)
这个页面文件名:getAuthorAndOrgInfoDate.jsp
<%
//得到日期
Calendar nCalendar=Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String currentDateTime=formatter.format(nCalendar.getTime());
formatter = new SimpleDateFormat("yyyy-MM-dd");
String currentDate=formatter.format(nCalendar.getTime());
DepModel depModel=new DepModel();
//得到部门信息
depModel=new DepProxy().getDepModelByDepID(Integer.parseInt(deptmentID));
String depPrincipal=depModel.getDepPrincipal(); //部门负责人
//这段JSP代码唯一有用的一段。
String value=orgName+";"+username+";"+userID+";"+deptmentID+";"+depPrincipal+";"+currentDateTime+";"+currentDate;
System.out.println("value========="+value);
%>
<BODY>
<form name="thform">
<input type="hidden" name="authorInfo" value="<%=value%>">
</form>
<script language="JavaScript">
var formValue = thform.authorInfo.value;
window.returnValue = thform.authorInfo.value;//这个东东很重要。参数就从这里传出去的。
window.close();
</script>
</BODY>
有了参数那我们就要取这个对数了。可以在任何页面里用以下方法取它。一看就知道,下面是javascript代码
var formValue =window.showModalDialog("/application/draft/getAuthorAndOrgInfo.jsp","getDocNo","scroll:0;status:0;help:0;resizable:0;dialogWidth:0px;dialogHeight:0px");
var dep=formValue.split(";")[0];
var author=formValue.split(";")[1];
var authorid=formValue.split(";")[2];
var orgid=formValue.split(";")[3];
var userpid=formValue.split(";")[4];
var currentDateTime=formValue.split(";")[5];
var currentDate=formValue.split(";")[6];
剩下的就不多说了,要用的话,直接用以上变量赋值就可以了,用那个取那个,少了再加,多了也不嫌,根据需要自己也可以定制。