在web.xml中添加代码:
<!-- 配置DWR -->
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>classes</param-name>
<param-value>java.lang.Object</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
在WEB-INF目录下加入dwr.xml 代码如下:
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://www.getahead.ltd.uk/dwr//dwr20.dtd">
<dwr>
<allow>
<create creator="spring" javascript="DwrAction" > <!--方法名称-->
<param name="beanName" value="dwrAction"></param> <!--对应applicationContext.xml中bean的名称-->
</create>
</allow>
</dwr>
applicationContext.xml中bean的配置如下:
<!-- DWR 配置 -->
<bean name="dwrdao" class="com.jjq.oa.dao.impl.DwrDaoImpl">
<property name="hibernateTemplate">
<ref bean="hibernateTemplate" />
</property>
</bean>
<bean name="dwrAction" class="com.jjq.oa.web.struts.action.DwrAction">
<property name="dwrdao">
<ref bean="dwrdao" />
</property>
</bean>
action中的代码如下(DwrAction.JAVA)
/**
* @creator 季枫
* @create-time 2009-2-6 下午02:48:07
*/
package com.jjq.oa.web.struts.action;
import java.util.List;
import com.jjq.oa.DwrDao;
import com.jjq.oa.dao.po.Activitiestypes;
public class DwrAction {
/**
* @creator 季枫
* @create-time 2009-2-6 下午02:48:07
* @note
*/
DwrDao dwrdao;
public void setDwrdao(DwrDao dwrdao) {
this.dwrdao = dwrdao;
}
public String [] getActivitiestypes(){
List activitiestypes =dwrdao.activitiestypes();
String result[]= new String[activitiestypes.size() * 2];
Object [] object=null;
int b=0;
for(int i=0,j=0;i<activitiestypes.size();i++){
object = (Object [])activitiestypes.get(i);
result[j]=((Integer)object[0]).intValue()+"";
result[j+1]=(String)object[1];
System.out.println(result[j]+"|"+result[j+1]);
j=j+2;
}
return result;
}
}
接口文件代码如下(DwrDao.java):
/**
* @creator 季枫
* @create-time 2009-2-6 下午02:51:19
*/
package com.jjq.oa.dao;
import java.util.List;
public interface DwrDao {
/**
*
*@author 季枫
*@create-time 2009-2-6 下午02:52:48
*@note 活动类别
*/
public List activitiestypes();
}
Dao的实现类代码如下(DwrDaoImpl.java):
/**
* @creator 季枫
* @create-time 2009-2-6 下午02:53:27
*/
package com.jjq.oa.dao.impl;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.jjq.oa.dao.DwrDao;
import com.jjq.oa.dao.po.Activitiestypes;
public class DwrDaoImpl extends HibernateDaoSupport implements DwrDao{
public List activitiestypes() {
/**
* @creator 季枫
* @create-time 2009-2-6 下午02:53:27
* @note
*/
List rs = getHibernateTemplate().find("select id,name from Activitiestypes");
return rs;
}
/**
* @creator 季枫
* @create-time 2009-2-6 下午02:53:27
* @note
*/
}
前台JSP调用的代码如下:
<script>
DwrAction.getActivitiestypes(back); //活动类别
function back(arr){
alert(arr.length);
var str1="<select><option value=\'999\'>请选择</option>";
for (i=0,j=1;i<arr.length;i++)
{
str1+="<option value=\'"+arr[i]+"\'>"+arr[j]+"</option>";
j=j+2;
i++;
}
str1+="</select>";
alert(str1);
classid.innerHTML=str1;
}
</script>
阅读全文
没事做弄的大开水安排程序
2009-02-05
java
85 views
0
action中的主要代码如下
public String mklist(){
String [] name={"廖明焱","张杰","向志勇","陈刚","邓正超","罗佳","张云峰","王磊"};
Date date=new Date();
date=getPreviousWeekDay(date);
tdate=new ArrayList<kaishui>();
for (int i=1,j=0;i<100;i++,j++)
{
ks=new kaishui();
date=getNextWeekDay(date);
ks.setDatestr(date.getDate());
ks.setMon(date.getMonth()+1);
ks.setYear(date.getYear()+1900);
ks.setTname(name[j]);
//System.out.println(date);
tdate.add(ks);
if (j==7)
{
j=-1;
}
}
//System.out.println(tdate.size());
return SUCCESS;
}
public static synchronized java.util.Date getNextWeekDay(Date date )
{
GregorianCalendar gc = ( GregorianCalendar ) Calendar.getInstance();
gc.setTime( date );
switch ( gc.get( Calendar.DAY_OF_WEEK ) )
{
case ( Calendar.FRIDAY ):
gc.add( Calendar.DATE, 1 );
break;
case ( Calendar.SATURDAY ):
gc.add( Calendar.DATE, 1 );
break;
default:
gc.add( Calendar.DATE, 1 );
break;
}
//System.out.println(gc);
return gc.getTime();
}
public static synchronized java.util.Date getPreviousWeekDay(Date date){
GregorianCalendar gc = ( GregorianCalendar ) Calendar.getInstance();
gc.setTime( date );
/**
* 详细设计:
* 1.如果date是星期日,则减3天
* 2.如果date是星期六,则减2天
* 3.否则减1天
*/
switch ( gc.get( Calendar.DAY_OF_WEEK ) )
{
case ( Calendar.MONDAY ):
gc.add( Calendar.DATE, -3 );
break;
case ( Calendar.SUNDAY ):
gc.add( Calendar.DATE, -2 );
break;
default:
gc.add( Calendar.DATE, -1 );
break;
}
return gc.getTime();
}
页面的源码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'user_klist.jsp' starting page</title>
<link rel="stylesheet" type="text/css" href="../css/users.css">
</head>
<body>
<div class="klist">
<s:iterator value="tdate">
<li><s:property value="year"/>年<s:property value="mon"/>月<s:property value="datestr"/>日</li>
<li>姓名:<s:property value="tname"/></li>
</s:iterator>
</div>
</body>
</html>
CSS文件源码:
.klist {300px;overflow: hidden;margin-left: 10px;}
.klist li{float:left;148px;overflow: hidden; border:1px #A6C1E8 solid;text-align: center;}