论坛首页 Web前端技术论坛

项目中重要的代码

浏览 1307 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2008-06-11  
DWR
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!--配置spring的applicationContext配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext*.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!--配置struts的控制器组件 -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml
</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<!--该操作用于对dwr进行配置 -->
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
dwr.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">
<!--<!DOCTYPE dwr SYSTEM "dwr20.dtd" >-->
<dwr>
<allow>
<create javascript="showVote" creator="spring" scope="script">
<param name="beanName" value="voteDwr" />
<include method="getAllVote" />
<include method="createVote" />
<include method="deleteVote" />
<include method="createVoteCounter" />
<include method="findVoteByid" />
<include method="updateVote"/>
</create>
<convert match="org.david.hib.model.Vote" converter="bean">
<param name="include" value="id,name,counter" />
</convert>
</allow>
</dwr>
struts-config.xml
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
application.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>


<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</property>
<property name="url">
<value>jdbc:microsoft:sqlserver://localhost:1433</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>sa</value>
</property>
</bean>
<bean id="sessionFactoryId"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="datasource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/accp/hib/model/CustomerType.hbm.xml</value>
<value>org/accp/hib/model/ManagerInfo.hbm.xml</value>
<value>org/accp/hib/model/StockIn.hbm.xml</value>
<value>org/accp/hib/model/Consume.hbm.xml</value>
<value>org/accp/hib/model/Hardware.hbm.xml</value>
<value>
org/accp/hib/model/ThingBusinessSingle.hbm.xml
</value>
<value>org/accp/hib/model/HandDuty.hbm.xml</value>
<value>org/accp/hib/model/StockOut.hbm.xml</value>
<value>
org/accp/hib/model/RoomBusinessSingle.hbm.xml
</value>
<value>org/accp/hib/model/RoomType.hbm.xml</value>
<value>org/accp/hib/model/CheckOut.hbm.xml</value>
<value>org/accp/hib/model/ChangeRoom.hbm.xml</value>
<value>org/accp/hib/model/ThingInfo.hbm.xml</value>
<value>org/accp/hib/model/Type.hbm.xml</value>
<value>org/accp/hib/model/BusinessTotal.hbm.xml</value>
<value>org/accp/hib/model/RoomInfo.hbm.xml</value>
<value>org/accp/hib/model/ListConsume.hbm.xml</value>
<value>org/accp/hib/model/CustomerInfo.hbm.xml</value>
<value>org/accp/hib/model/Preconcert.hbm.xml</value>
<value>org/accp/hib/model/OpenInfo.hbm.xml</value>
<value>org/accp/hib/model/SysEmail.hbm.xml</value>
<value>org/accp/hib/model/HardwareList.hbm.xml</value></list>
</property></bean>
</beans>
application-cmd.xml
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactoryId" />
</property>
</bean>
<!--设置事务通知对象-->
<bean id="interceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!--指定所要引用的事物管理; -->
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<!--指定当触发了目标对象的哪些方法时,引用事物管理 -->
<property name="transactionAttributes">
<props>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!--定义代理,该代理用于指定一个通知对象,让它监视住某个对象
注意:不需要设置该代理对象的id属性和name属性;-->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定所要做通知的通知对象 -->
<property name="interceptorNames">
<list>
<value>interceptor</value>
</list>
</property>
<!--指定所要拦截目标对象; -->
<property name="beanNames">
<list>
<value>roomInfoCmd</value>
</list>
</property>
</bean>

jsp页面
<%@ page language="java" pageEncoding="gbk"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript"
src="/BallotSystem/dwr/interface/showVote.js"></script>
<script type="text/javascript" src="/BallotSystem/dwr/engine.js"></script>
<script type="text/javascript" src="/BallotSystem/dwr/util.js"></script>
<script type="text/javascript">
/*总票数*/
var totalCount=0;
var begin = 0;
var voteId=null;
var updateId=null;
/*将数据库中的数据加载到也页面*/
function init()
{
totalCount=0;
begin=0;
$("voteResult").style.display="none";
$("votePage").style.display="";
$("voteManage").style.display="none";
showVote.getAllVote(createTable);
}
/*将读取出来的数据填充到表格中*/
function createTable(data)
{
DWRUtil.removeAllRows("allVote");
DWRUtil.setEscapeHtml(false);
DWRUtil.addRows("allVote",data,cellfuncs,options);
}
/*行处理函数*/
var cellfuncs=[
function(data)
{
return "<input type='radio' value='"+data.id+"' name='type' onchange='createVoteId(this.value)'>";
},
function(data)
{
return data.name;
}
];
/*行样式处理*/
var options =
{
rowCreator:function(options)
{
var row = document.createElement("tr");
row.style.backgroundColor = "white";
return row;
}
};
/*获取点击事件*/
function getClick(value)
{
if(value==1)
{
/*投票*/
if(voteId==null)
{
alert("请选择选项!");
return ;
}
showVote.createVoteCounter(voteId);
voteId=null;
$("voteResult").style.display="";
$("votePage").style.display="none";
showVote.getAllVote(createTableSelect);
}
else if(value==2)
{
/*查看投票*/
$("voteResult").style.display="";
$("votePage").style.display="none";
showVote.getAllVote(createTableSelect);
}
else
{
/*管理投票*/
totalCount=0;
begin=0;
$("voteResult").style.display="none";
$("votePage").style.display="none";
$("voteManage").style.display="";
showVote.getAllVote(createTableManage);
}
}
/*查看投票结果*/
function createTableSelect(data)
{
for(var i=0;i<data.length;i++)
{
totalCount=totalCount+data[i].counter;
}
DWRUtil.removeAllRows("allVoteResult");
DWRUtil.setEscapeHtml(false);
DWRUtil.addRows("allVoteResult",data,cellfuncResult,options);
}
/*将查看结果信息添加到表格中*/
var cellfuncResult=[
function(data){
begin=begin+1;
return "["+begin+"]";
},
function(data)
{
return data.name;
},
function(data)
{
var mid=(data.counter/totalCount)*100;
var hr="<img src='image/mm.jpg' width='"+mid*5+"' height='25'>";
var str = "投票率:   "+hr+Math.round(mid)+"%  [得:"+data.counter+"票 共: "+totalCount+"票]";
return str;
}
];
/*添加投票选项*/
function createVote()
{
var projectName=$("projectName").value;
if(projectName==""||projectName.length<1)
{
alert("请输入!");
return ;
}
$("projectName").value="";
DWREngine.beginBatch();
showVote.createVote(projectName);
showVote.getAllVote(createTableManage);
DWREngine.endBatch();
}
/*管理投票部分*/
function createTableManage(data)
{
totalCount=0;
begin=0;
for(var i=0;i<data.length;i++)
{
totalCount=totalCount+data[i].counter;
}
DWRUtil.removeAllRows("allVoteManage");
DWRUtil.setEscapeHtml(false);
DWRUtil.addRows("allVoteManage",data,cellfuncManage,options);
}
/*管理投票的行处理*/
var cellfuncManage=[
function(data){
begin=begin+1;
return "["+begin+"]";
},
function(data)
{
return data.name;
},
function(data)
{
var mid=(data.counter/totalCount)*100;
var hr="<img src='image/mm.jpg' width='"+mid*4+"' height='25'>";
var str = "投票率:   "+hr+Math.round(mid)+"%  [得:"+data.counter+"票 共: "+totalCount+"票]";
return str;
},
function(data)
{
return "<a href='#' name='"+data.id+"' onclick='showUpdateVote(this.name)'>[修改]</a>";
},
function(data)
{
return "<a href='#' name='"+data.id+"' onclick='deleteVote(this.name)'>[删除]</a>";
}
];
/*删除投票*/
function deleteVote(value)
{
DWREngine.beginBatch();
showVote.deleteVote(value);
showVote.getAllVote(createTableManage);
DWREngine.endBatch();
}
/*给投票id赋值*/
function createVoteId(value)
{
voteId=value;
}
/*显示修改投票项*/
function showUpdateVote(value)
{
$("voteManage").style.display="none";
$("voteUpdate").style.display="";
showVote.findVoteByid(value,function(data){
DWRUtil.setValues(data);
});
updateId=value;
}
/*修改投票项,返回*/
function updateReturn()
{
$("voteManage").style.display="";
$("voteUpdate").style.display="none";
}
/*修改投票项*/
function updateVote()
{
var vote={id:updateId,name:null,counter:null};
DWREngine.beginBatch();
DWRUtil.getValues(vote);
updateReturn();
showVote.updateVote(vote);
showVote.getAllVote(createTableManage);
DWREngine.endBatch();
}
</script>
</head>

<body onload="init();">
<div id="votePage">
<table bgcolor="sky-blue" border="1" width="950">
<tr>
<th width="150">
投票
</th>
<th align="center" width="800">
选项
</th>
</tr>
<tbody id="allVote">
</tbody>
<tr>
<th align="center" colspan="2">
<a href="#" onclick="getClick(this.name)" name="1"> [投票] </a>
<a href="#" onclick="getClick(this.name)" name="2"> [查看投票结果] </a>
<a href="#" onclick="getClick(this.name)" name="3"> [管理投票] </a>
</th>
</tr>
</table>
</div>
<div id="voteResult" style="display: none">
<table bgcolor="sky-blue" border="1" width="950">
<tr>
<th width="150">
序号
</th>
<th width="150">
选项
</th>
<th width="650">
投票率
</th>
</tr>
<tbody id="allVoteResult">
</tbody>
<tr>
<th colspan="3" align="center">
<a href="#" onclick="init()"> [返回首页] </a>
</th>
</tr>
</table>
</div>
<div id="voteManage" style="display: none">
<center>
<table bgcolor="sky-blue" border="1" width="600">
<tr>
<th width="200">
添加投票项目
</th>
<td width="300">
<input type="text" id="projectName">
</td>
<td>
<input type="button" value="添加" onclick="createVote()">
</td>
</tr>
</table>
</center>
<br>
<table bgcolor="sky-blue" border="1" width="950">
<tr>
<th width="120">
序号
</th>
<th width="120">
选项
</th>
<th width="550">
投票率
</th>
<th colspan="2">
行为
</th>
</tr>
<tbody id="allVoteManage">
</tbody>
<tr>
<th colspan="5" align="center">
<a href="#" onclick="init()"> [返回首页] </a>
</th>
</tr>
</table>
</div>
<div id="voteUpdate" style="display: none">
<center>
<table bgcolor="sky-blue" border="1" width="450">
<tr>
<th align="center" colspan="2">
修改投票选项
</th>
</tr>
<tbody>
<tr bgcolor="white">
<th align="center">
项目名称
</th>
<td align="left">
<input type="text" id="name">
</td>
</tr>
<tr bgcolor="white">
<th align="center">
票数
</th>
<td align="left">
<input type="text" id="counter">
</td>
</tr>
</tbody>
<tr>
<th align="center" colspan="2">
<a href="#" onclick="updateVote();"> [修改] </a>
<a href="#" onclick="updateReturn();"> [返回] </a>
</th>
</tr>
</table>
</center>
</div>
</body>
</html>


论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics