2008年8月26日星期二

JQuery Grid插件Flexigrid使用

Flexigrid界面风格类似于ext,是一个比较强大的ajax数据显示grid插件,在此地址下载:http://www.webplicity.net/flexigrid/
下载加入工程,官方的例子说的很明白了,这里就不多说了。
需要注意的是在使用json返回时必须按照下面的格式拼装:
{
"total":200, //数据总数
"page":2, //页码(第几页)等等,相关参数可以在他的源码中找到
"rows":[
{"id":"1","cell":["a","b","c","e"]},
{"id":"2","cell":["a","b","c","e"]},
{"id":"3","cell":["a","b","c","e"]},
{"id":"4","cell":["a","b","c","e"]},
{"id":"5","cell":["a","b","c","e"]},
{"id":"6","cell":["a","b","c","e"]},
{"id":"7","cell":["a","b","c","e"]},
{"id":"8","cell":["a","b","c","e"]},
]}

返回json对象中(也就是个字符串)"row" 和其对应的数据必须按照此格式输出,要不然页面会没办法展现数据,使用下面的方法:


public void getData() {
int page = Integer.parseInt(request.getParameter("page"));
int totalUser = DBManager.getTotalUser();

List userList = DBManager.getUsers();

Map map = new HashMap();
map.put("page", page);
map.put("total", totalUser);

List mapList = new ArrayList();

for (int i = 0; i < userList.size(); i++) {
User u = userList.get(i);
Map cellMap = new HashMap();
cellMap.put("id", i);
cellMap.put("cell", new Object[] { u.getId(), u.getUserName(),u.getUserPass() });
mapList.add(cellMap);
}

map.put("rows", mapList);

JSONObject object = new JSONObject(map);
System.out.println(object.toString());


}

mapList用来存放数据,但是里面的每条数据都是一个map,map必须有一个键为“id”和对应的值,和键为“cell”和对应的值,而cell对应就是真正的数据了,这里是user,而且cell的值队必须是object[]数组,可以把user的各个属性值放进去,但是这样
cellMap.put("cell",u)是不行的,不能直接对应user。而页面取值其实是根据这个object数组的索引来取的,这要注意。其他很简单了。

标签:

2008年8月24日星期日

Spring配置文件--Typical

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<!--

- Application context definition for PetClinic on Hibernate.

-->

<beans>

<!-- ========================= RESOURCE DEFINITIONS ========================= -->

<!-- Configurer that replaces ${...} placeholders with values from a properties file -->

<!-- (in this case, JDBC-related settings for the dataSource definition below) -->

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="location" value="/WEB-INF/jdbc.properties"/>

</bean>

<!-- Local DataSource that works in any environment -->

<!-- Note that DriverManagerDataSource does not pool; it is not intended for production -->

<!-- See JPetStore for an example of using Commons DBCP BasicDataSource as alternative -->

<!-- See Image Database for an example of using C3P0 ComboPooledDataSource as alternative -->

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<property name="driverClassName" value="${jdbc.driverClassName}"/>

<property name="url" value="${jdbc.url}"/>

<property name="username" value="${jdbc.username}"/>

<property name="password" value="${jdbc.password}"/>

</bean>

<!-- JNDI DataSource for J2EE environments -->

<!--

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

<property name="jndiName" value="java:comp/env/jdbc/petclinic"/>

</bean>

-->

<!-- Hibernate SessionFactory -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource"/>

<property name="mappingResources">

<value>mobile.hbm.xml</value>

</property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">${hibernate.dialect}</prop>

<prop key="hibernate.show_sql">true</prop>

<prop key="hibernate.generate_statistics">true</prop>

</props>

</property>

<property name="eventListeners">

<map>

<entry key="merge">

<bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/>

</entry>

</map>

</property>

</bean>



<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

<property name="sessionFactory" ref="sessionFactory"/>

</bean>



<!-- Transaction manager that delegates to JTA (for a transactional JNDI DataSource) -->

<!--

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>

-->



<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->

<!--

- PetClinic's central data access object: Hibernate implementation.

-->

<bean id="mobileTarget" class="com.gomt.stbc.hibernate.HibernateMobile">

<property name="sessionFactory" ref="sessionFactory"/>

</bean>

<!--

- Transactional proxy for PetClinic's central data access object.

-

- Defines specific transaction attributes with "readOnly" markers,

- which is an optimization that is particularly valuable with Hibernate

- (to suppress unnecessary flush attempts for read-only operations).

-

- Note that in a real-life app with multiple transaction proxies,

- you will probably want to use parent and child bean definitions

- as described in the manual, to reduce duplication.

-->

<bean id="mobile" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

<property name="transactionManager" ref="transactionManager"/>

<property name="target" ref="mobileTarget"/>

<property name="transactionAttributes">

<props>

<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>

<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>

<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>

<prop key="store*">PROPAGATION_REQUIRED</prop>

</props>

</property>

</bean>



<!-- Hibernate 3.0's JMX statistics service -->

<!-- Implements the StatisticsServiceMBean management interface -->

<!--

<bean name="petclinic:type=HibernateStatistics" class="org.hibernate.jmx.StatisticsService">

<property name="sessionFactory" ref="sessionFactory"/>

</bean>-->

<!-- ========================= JMX EXPORTER DEFINITION ========================= -->

<!--

- Exporter that exposes Hibernate 3.0's statistics service via JMX.

- Autodetects the statistics service, which is a standard MBean,

- using its bean name as JMX object name.

-

- By default, the standard MBeanServerFactory.findMBeanServer method will be used

- to determine the MBeanServer. Unfortunately, this does not work on WebLogic <= 8.1:

- you need to comment in the WebLogicMBeanServerFactoryBean definition on WebLogic,

- specifying appropriate configuration values there.

-->

<!--

<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter">

<property name="autodetect" value="true"/>

</bean>-->

<!-- Comment the following in on WebLogic <= 8.1, which doesn't support -->

<!-- the standard MBeanServerFactory.findMBeanServer lookup mechanism. -->

<!--

<property name="server">

<bean class="org.springframework.jmx.support.WebLogicJndiMBeanServerFactoryBean"/>

</property>

-->

</beans>

标签:

2008年8月18日星期一

JQuery插件--ingrid使用

本实例使用struts2进行演示 ingrid.js是一款ajax,可以用来实现页面数据展现
ingrid.js 及jquery 下载:
http://download284.mediafire.com/eh2zwxytoybg/iui78qsoche/ingrid.tar.gz
下载后在工程WebContent下新建JS文件夹,将下载的文件解压后放进去.

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="<s:url action="getUserListForTable" namespace="/my"
>">Show Users</a>


</body>
</html>



userList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="<s:url value='/css/ingrid.css' />"
type="text/css" media="screen" />
<script type="text/javascript" src="<s:url value="/js/jquery.js" />"></script>
<script type="text/javascript" src="<s:url value="/js/ingrid.js" />"></script>

<script type="text/javascript">
document.write(<s:property value="totalRow"/>);
$(document).ready(
function() {
var mygrid1=$("#table1").ingrid({
url: '<s:url action="getPageUserList" namespace="my"/>',
initialLoad: true,
paging: true,
rowClasses: ['grid-row-style1','grid-row-style1','grid-row-style2','grid-row-style1','grid-row-style1','grid-row-style3'],
pageNumber:1,
totalRecords:<s:property value="totalRow"/>,
recordsPerPage:<s:property value="size"/>,
height: 350

});

$('#getTotal').click(function(){
// the 'g' object is ingrid - call methods like so:
alert(mygrid1.g.p.getTotalRecords());
});

}
);
</script>

</head>
<body class="tundra">
<table id="table1">
<thead>
<tr>
<th>User ID</th>
<th>User Name</th>
<th>Password</th>
<th>Birthday</th>
</tr>
</thead>
<tbody>
<s:iterator value="userList" status="user">
<tr>
<td><s:property value="id" /></td>
<td><s:property value="uName" /></td>
<td><s:property value="uPass" /></td>
<td><s:property value="birthday" /></td>
</tr>
</s:iterator>
</tbody>
</table>

<a href="#" id="getTotal">total rows</a>
</body>
</html>


table.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>


<table>
<tbody>
<s:iterator value="userList" status="user">
<tr>
<td><s:property value="id" /></td>
<td><s:property value="uName" /></td>
<td><s:property value="uPass" /></td>
<td><s:property value="birthday" /></td>
</tr>
</s:iterator>
</tbody>
</table>

下面看看 action

public class TableAction extends ActionSupport implements Action {

private List userList;
private int totalRow;
private int size = 20;
private int page = 1;

@SuppressWarnings("unchecked")
public String getUserListForTable() {
DBManager mgr = new DBManager();
int start = (page - 1) * size;
int end = start + size;
if (totalRow == 0) {
try {
mgr.openDB();
totalRow = mgr.getTotalRow();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
try {
mgr.openDB();
userList = mgr.getUserInfoList(start, end);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return SUCCESS;

}

public String getPageUserList() {

int start = (page - 1) * size;
int end = start + size;

System.out.println(totalRow);
DBManager mgr = new DBManager();
try {
mgr.openDB();
userList = mgr.getUserInfoList(start, end);
mgr.closeDB();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return SUCCESS;

}

public List getUserList() {
return userList;
}

Get/Set .........

}
为了简单一点,userInfo就是普通的java类,包含几个基本数据类型,DBManager就是打开数据库取数据而已,主要方法如下:

查询从startRow到endRow之间的数据
List DBManager.getUserInfoList(int startRow, int endRow)
得到总行数
int DBManager .getTotalRow()

struts.xml 配置:
<action name="getUserListForTable" class="home.dly.TableAction" method="getUserListForTable">
<result name="success">/userList.jsp</result>
</action>
<action name="getPageUserList" class="home.dly.TableAction" method="getPageUserList">
<result name="success">/table.jsp</result>
</action>

在userList.jsp中的javascript
<script type="text/javascript">
document.write(<s:property value="totalRow"/>);
$(document).ready(
function() {
var mygrid1=$("#table1").ingrid({
url: '<s:url action="getPageUserList" namespace="my"/>', //这里指定再次请求数据时的URL,也就是Action.如翻页时
initialLoad: true,
paging: true, //是否分页,默认为true
rowClasses: ['grid-row-style1','grid-row-style1','grid-row-style2','grid-row-style1','grid-row-style1','grid-row-style3'],
pageNumber:1,
totalRecords:<s:property value="totalRow"/>, //数据的总行数.这个属性不是必须的,但是想要页面显示总页数就必须有了.
//必须有了.这里可以混合struts2的标签将anction中的数据取出.
recordsPerPage:<s:property value="size"/>, //每页大小,可以混合struts2的标签将anction中的数据取出,
height: 350

});

}
);
</script>

table.jsp则是专门用来显示数据的, 以后的每次翻页请求数据都会显示在table.jsp中,因为action中配置了是转向table.jsp的,而userList.jsp每次请求数据后会将table.jsp中的内容在取过来显示出来,好比 include一样.
最后注意一个小问题:
数据显示的页面userList.jsp的table需要<thead>部分,table.jsp不用,只要body就OK了!!!

标签:

Linux 常用的基本命令

uname  -a     查看内核版本       
ls  -al     显示所有文件的属性
pwd          显示当前路径        
cd  -     返回上一次目录      cd  ~     返回主目录
date  s       设置时间、日期          
cal       显示日历      cal  2006
bc           计算器具               
man   &  info      帮助手册
locale      显示当前字体      locale  -a     所有可用字体      /etc/sysconfig/i18n设置文件
LANG=en     使用英文字体            
sync        将数据同步写入硬盘        
shutdonw  -h  now  &  half  &  poweroff   关机
reboot      重启                   
startx   &   init  5    进入图形介面
/work   &  ?work     向上、下查找文档内容
chgrp       改变档案群组   chgrp  testing  install.log    
chown      改变所属人    chown  root:root  install.log
chmod       改变属性      chmod  777  install.log      read=4   write=2   execute=1
cp    复制    cp  filename
rm    删除文件   rm  -rf  filename    强制删除文件
rmdir    删除文件夹
mv   移动     mv  123.txt  222.txt   重命名
mkdir      创建文件夹
touch      创建文件   更新当前时间
cat        由第一行开始显示      cat  ¦more   分页
nl         在内容前加行号
more   &   less    一面一面翻动
head  -n  filename    显示第N行内容
tail  -n  filename   显示后N行内容
od         显示非纯文档
df  -h  显示分区空间
du   显示目录或文件的大小
fdisk    分区设置     fdisk  -l  /dev/hda   显示硬盘分区状态
mkfs     建立各种文件系统   mkfs  -t  ext3   /dev/ram15   
fsck     检查和修复LINUX档案
ln       硬链接    ln  -s   软件链接
whereis    查找命令
locate     查找
find       查找    find  /  -name  "***.***"
which      查看工具
whoami     显示当前用户
gcc  -v     查看GCC版本
chattr  +i  filename   禁止删除    chattr  -i  filename   取消禁止
lsattr     显示隐藏档属性
updatedb   更新资料库
mke2fs     格式化    mkfs  -t  ext3 
dd  if=/etc/passwd  of=/tmp/passwd.bak     备份
mount      列出系统所有的分区
mount  -t  iso9660  /dev/cdrom  /mnt/cdrom    挂载光盘
mount  -t  vfat  /dev/fd0  /mnt/floppy        挂载软盘
mount  -t  vfat  -o  iocharset=utf8,umask=000  /dev/hda2  /mnt/hda2    挂载fat32分区
mount  -t  ntfs  -o  nls=utf8,umask=000  /dev/hda3  /mnt/hda3          挂载ntfs分区
Linux-NTFS  Project:  http://linux-ntfs.sourceforge.net/
umount  /mnt/hda3   缷载
ifconfig    显示或设置网络设备
service  network  restart    重启网卡  
ifdown  eth0   关闭网卡
ifup  eth0     开启网卡
clear     清屏
history     历史记录        !55   执行第55个指令
stty    设置终端     stty  -a
fdisk  /mbr    删除GRUB
at      僅進行一次的工作排程
crontab    循環執行的例行性命令     [e]编辑,[l]显示,[r]删除任务
&        后台运行程序     tar  -zxvf  123.tar.gz  &  --------- >后台运行
jobs     观看后台暂停的程序    jobs  -l
fg       将后台程序调到前台    fg  n  ------ >n是数字,可以指定进行那个程序
bg       让工作在后台运行
kill     结束进程     kill  -9  PID      [9]强制结束,[15]正常结束,[l]列出可用的kill信号
ps  aux   查看后台程序   
top      查看后台程序    top  -d  2     每两秒更新一次         top  -d  2  -p10604    观看某个PID
        top  -b  -n  2  >  /tmp/top.txt  ----- >將  top  的資訊進行  2  次,然後將結果輸出到  /tmp/top.txt    
pstree    以树状图显示程序     [A]以  ASCII  來連接,  列出PID,  [p]列出帐号
killall    要刪除某個服務     killall  -9  httpd
free       显示内存状态      free  -m   -------- >以M为单位显示
uptime     显示目前系统开机时间
netstat    显示网络状态     netstat  -tulnp------ >找出目前系統上已在監聽的網路連線及其  PID
dmesg      显示开机信息     demsg  ¦  more
nice       设置优先权       nice  -n  -5  vi  &  ----- >用  root  給一個  nice  植為  -5  ,用於執行  vi 
renice     调整已存在优先权
runlevel   显示目前的runlevel
depmod     分析可载入模块的相依性
lsmod      显示已载入系统的模块
modinfo    显示kernel模块的信息
insmod     载入模块
modprobe    自动处理可载入模块
rmmod      删除模块
chkconfig    检查,设置系统的各种服务      chkconfig  --list  ----- >列出各项服务状态
ntsysv      设置系统的各种服务
cpio       备份文件

标签:

Linux 压缩-解压 命令集

.tar
解包: tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是压缩!)
---------------------------------------------
.gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName
.tar.gz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName
---------------------------------------------
.bz2
解压1:bzip2 -d FileName.bz2
解压2:bunzip2 FileName.bz2
压缩: bzip2 -z FileName
.tar.bz2
解压:tar jxvf FileName.tar.bz2
压缩:tar jcvf FileName.tar.bz2 DirName
---------------------------------------------
.bz
解压1:bzip2 -d FileName.bz
解压2:bunzip2 FileName.bz
压缩:未知
.tar.bz
解压:tar jxvf FileName.tar.bz
压缩:未知
---------------------------------------------
.Z
解压:uncompress FileName.Z
压缩:compress FileName
.tar.Z
解压:tar Zxvf FileName.tar.Z
压缩:tar Zcvf FileName.tar.Z DirName
---------------------------------------------
.tgz
解压:tar zxvf FileName.tgz
压缩:未知
.tar.tgz
解压:tar zxvf FileName.tar.tgz
压缩:tar zcvf FileName.tar.tgz FileName
---------------------------------------------
.zip
解压:unzip FileName.zip
压缩:zip FileName.zip DirName
---------------------------------------------
.rar
解压:rar a FileName.rar
压缩:r ar e FileName.rar


rar请到:http://www.rarsoft.com/download.htm 下载!
解压后请将rar_static拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp rar_static /usr/bin/rar
---------------------------------------------
.lha
解压:lha -e FileName.lha
压缩:lha -a FileName.lha FileName

lha请到:http://www.infor.kanazawa-it.ac.jp/.../lhaunix/下载!
>解压后请将lha拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp lha /usr/bin/
---------------------------------------------
.rpm
解包:rpm2cpio FileName.rpm | cpio -div
---------------------------------------------
.tar .tgz .tar.gz .tar.Z .tar.bz .tar.bz2 .zip .cpio .rpm .deb .slp .arj .rar .ace .lha .lzh
.lzx .lzs .arc .sda .sfx .lnx .zoo .cab .kar .cpt .pit .sit .sea
解压:sEx x FileName.*
压缩:sEx a FileName.* FileName

sEx只是调用相关程序,本身并无压缩、解压功能,请注意!
sEx请到: http://sourceforge.net/projects/sex下载!
解压后请将sEx拷贝到/usr/bin目录(其他由$PATH环境变量指定的目录也可以):
[root@www2 tmp]# cp sEx /usr/bin/

标签:

Linux文件系统结构

linux目录架构
/    根目录
/bin     常用的命令  binary  file  的目錄
/boot    存放系统启动时必须读取的档案,包括核心  (kernel)  在内
     /boot/grub/menu.lst    GRUB设置
     /boot/vmlinuz    内核
     /boot/initrd      核心解壓縮所需  RAM  Disk
/dev     系统周边设备     
/etc     系统相关设定文件
     /etc/DIR_COLORS    设定颜色
     /etc/HOSTNAME    设定用户的节点名
     /etc/NETWORKING    只有YES标明网络存在
     /etc/host.conf  文件说明用户的系统如何查询节点名
     /etc/hosts  设定用户自已的IP与名字的对应表
     /etc/hosts.allow  设置允许使用inetd的机器使用 
     /etc/hosts.deny  设置不允许使用inetd的机器使用
     /etc/hosts.equiv  设置远端机不用密码
     /etc/inetd.conf  设定系统网络守护进程inetd的配置
     /etc/gateways  设定路由器
     /etc/protocols  设定系统支持的协议
     /etc/named.boot  设定本机为名字服务器的配置文件
     /etc/sysconfig/network-scripts/ifcfg-eth0    设置IP
     /etc/resolv.conf     设置DNS  
     /etc/X11   X  Window的配置文件,xorg.conf  或  XF86Config  這兩個  X  Server  的設定檔
     /etc/fstab     记录开机要mount的文件系统
     /etc/inittab  设定系统启动时init进程将把系统设置成什么样的runlevel
     /etc/issue  记录用户登录前显示的信息
     /etc/group  设定用户的组名与相关信息
     /etc/passwd  帐号信息
     /etc/shadow  密码信息
     /etc/sudoers  可以sudo命令的配置文件
     /etc/securetty  设定哪些终端可以让root登录
     /etc/login.defs  所有用户登录时的缺省配置
     /etc/exports  设定NFS系统用的
     /etc/init.d/    所有服務的預設啟動  script  都是放在這裡的,例如要啟動或者關閉
     /etc/xinetd.d/   這就是所謂的  super  daemon  管理的各項服務的設定檔目錄
     /etc/modprobe.conf    内核模块额外参数设定
     /etc/syslog.conf    日志设置文件
/home    使用者家目录
/lib     系统会使用到的函数库
     /lib/modules    kernel  的相关模块
     /var/lib/rpm    rpm套件安装处 
/lost+found     系統不正常產生錯誤時,會將一些遺失的片段放置於此目錄下
/mnt      外设的挂载点
/media    与/mnt类似
/opt      主机额外安装的软件
/proc     虚拟目录,是内存的映射
      /proc/version    内核版本
       /proc/sys/kernel    系统内核功能
/root     系统管理员的家目录
/sbin     系统管理员才能执行的指令
/srv      一些服務啟動之後,這些服務所需要取用的資料目錄
/tmp      一般使用者或者是正在執行的程序暫時放置檔案的地方
/usr      最大的目录,存许应用程序和文件
    /usr/X11R6:    X-Window目录 
    /usr/src:     Linux源代码
    /usr/include:系统头文件
    /usr/openwin  存放SUN的OpenWin 
    /usr/man  在线使用手册
    /usr/bin            使用者可執行的  binary  file  的目錄
    /usr/local/bin      使用者可執行的  binary  file  的目錄
    /usr/lib            系统会使用到的函数库
    /usr/local/lib      系统会使用到的函数库
    /usr/sbin           系统管理员才能执行的指令
    /usr/local/sbin     系统管理员才能执行的指令
/var    日志文件
    /var/log/secure     記錄登入系統存取資料的檔案,例如  pop3,  ssh,  telnet,  ftp  等都會記錄在此檔案中
    /var/log/wtmp       記錄登入者的訊息資料,  last
    /var/log/messages   幾乎系統發生的錯誤訊息
    /var/log/boot.log   記錄開機或者是一些服務啟動的時候,所顯示的啟動或關閉訊息
    /var/log/maillog    紀錄郵件存取或往來(  sendmail  與  pop3  )的使用者記錄
    /var/log/cron       記錄  crontab  這個例行性服務的內容
    /var/log/httpd,  /var/log/news,  /var/log/mysqld.log,  /var/log/samba,  /var/log/procmail.log:
    分別是幾個不同的網路服務的記錄檔

标签:

java--继承,多态,重载和重写

什么是多态?它的实现机制是什么呢?重载和重写的区别在那里?这就是这一次我们要回顾的四个十分重要的概念:继承、多态、重载和重写。

继承

简单的说,继承就是在一个现有类型的基础上,通过增加新的方法或者重定义已有方法(下面会讲到,这种方式叫重写)的方式,产生一个新的类型。继承是面向对象的三个基本特征--封装、继承、多态的其中之一,我们在使用JAVA时编写的每一个类都是在继承,因为在JAVA语言中,java.lang.Object类是所有类最根本的基类(或者叫父类、超类),如果我们新定义的一个类没有明确地指定继承自哪个基类,那么JAVA就会默认为它是继承自Object类的。

我们可以把JAVA中的类分为以下三种:

1. 普通类:使用class定义且不含有抽象方法的类。
2. 抽象类:使用abstract class定义的类,它可以含有,也可以不含有抽象方法。
3. 接口类:使用interface定义的类。


在这三种类型之间存在下面的继承规律:

* 普通类可以继承(extends)普通类,可以继承(extends)抽象类,可以继承(implements)接口。
* 抽象类可以继承(extends)普通类,可以继承(extends)抽象类,可以继承(implements)接口。
* 接口只能继承(extends)接口。


请注意上面三条规律中每种继承情况下使用的不同的关键字extends和implements,它们是不可以随意替换的。大家知道,一个普通类继承一个接口后,必须实现这个接口中定义的所有方法,否则就只能被定义为抽象类。我在这里之所以没有对implements关键字使用“实现”这种说法是因为从概念上来说它也是表示一种继承关系,而且对于抽象类implements接口的情况下,它并不是一定要实现这个接口定义的任何方法,因此使用继承的说法更为合理一些。

以上三条规律同时遵守下面这些约束:

1. 普通类和抽象类都只能最多继承一个普通类,或者最多继承一个抽象类,并且这两种情况是互斥的,也就是说它们要么继承一个普通类,要么继承一个抽象类。
2. 普通类、抽象类和接口在继承接口时,不受数量的约束,理论上可以继承无限多个接口。当然,对于普通类来说,它必须实现它所继承的所有接口中定义的全部方法。


继承给我们的编程带来的好处就是对原有类的复用(重用)。就像模块的复用一样,类的复用可以提高我们的开发效率,实际上,模块的复用是大量类的复用叠加后的效果。除了继承之外,我们还可以使用组合的方式来复用类。所谓组合就是把原有类定义为新类的一个属性,通过在新类中调用原有类的方法来实现复用。如果新定义的类型与原有类型之间不存在被包含的关系,也就是说,从抽象概念上来讲,新定义类型所代表的事物并不是原有类型所代表事物的一种,比如黄种人是人类的一种,它们之间存在包含与被包含的关系,那么这时组合就是实现复用更好的选择。下面这个例子就是组合方式的一个简单示例:
Java代码 复制代码

1. public class Sub {
2. private Parent p = new Parent();
3.
4. public void doSomething() {
5. // 复用Parent类的方法
6. p.method();
7. // other code
8. }
9. }
10.
11. class Parent {
12. public void method() {
13. // do something here
14. }
15. }

public class Sub {
private Parent p = new Parent();

public void doSomething() {
// 复用Parent类的方法
p.method();
// other code
}
}

class Parent {
public void method() {
// do something here
}
}


当然,为了使代码更加有效,我们也可以在需要使用到原有类型(比如Parent p)时,才对它进行初始化。

使用继承和组合复用原有的类,都是一种增量式的开发模式,这种方式带来的好处是不需要修改原有的代码,因此不会给原有代码带来新的BUG,也不用因为对原有代码的修改而重新进行测试,这对我们的开发显然是有益的。因此,如果我们是在维护或者改造一个原有的系统或模块,尤其是对它们的了解不是很透彻的时候,就可以选择增量开发的模式,这不仅可以大大提高我们的开发效率,也可以规避由于对原有代码的修改而带来的风险。

多态

多态是又一个重要的基本概念,上面说到了,它是面向对象的三个基本特征之一。究竟什么是多态呢?我们先看看下面的例子,来帮助理解:
Java代码 复制代码

1. //汽车接口
2. interface Car {
3. // 汽车名称
4. String getName();
5.
6. // 获得汽车售价
7. int getPrice();
8. }
9.
10. // 宝马
11. class BMW implements Car {
12. public String getName() {
13. return "BMW";
14. }
15.
16. public int getPrice() {
17. return 300000;
18. }
19. }
20.
21. // 奇瑞QQ
22. class CheryQQ implements Car {
23. public String getName() {
24. return "CheryQQ";
25. }
26.
27. public int getPrice() {
28. return 20000;
29. }
30. }
31.
32. // 汽车出售店
33. public class CarShop {
34. // 售车收入
35. private int money = 0;
36.
37. // 卖出一部车
38. public void sellCar(Car car) {
39. System.out.println("车型:" + car.getName() + " 单价:" + car.getPrice());
40. // 增加卖出车售价的收入
41. money += car.getPrice();
42. }
43.
44. // 售车总收入
45. public int getMoney() {
46. return money;
47. }
48.
49. public static void main(String[] args) {
50. CarShop aShop = new CarShop();
51. // 卖出一辆宝马
52. aShop.sellCar(new BMW());
53. // 卖出一辆奇瑞QQ
54. aShop.sellCar(new CheryQQ());
55. System.out.println("总收入:" + aShop.getMoney());
56. }
57. }

//汽车接口
interface Car {
// 汽车名称
String getName();

// 获得汽车售价
int getPrice();
}

// 宝马
class BMW implements Car {
public String getName() {
return "BMW";
}

public int getPrice() {
return 300000;
}
}

// 奇瑞QQ
class CheryQQ implements Car {
public String getName() {
return "CheryQQ";
}

public int getPrice() {
return 20000;
}
}

// 汽车出售店
public class CarShop {
// 售车收入
private int money = 0;

// 卖出一部车
public void sellCar(Car car) {
System.out.println("车型:" + car.getName() + " 单价:" + car.getPrice());
// 增加卖出车售价的收入
money += car.getPrice();
}

// 售车总收入
public int getMoney() {
return money;
}

public static void main(String[] args) {
CarShop aShop = new CarShop();
// 卖出一辆宝马
aShop.sellCar(new BMW());
// 卖出一辆奇瑞QQ
aShop.sellCar(new CheryQQ());
System.out.println("总收入:" + aShop.getMoney());
}
}


运行结果:

1. 车型:BMW 单价:300000
2. 车型:CheryQQ 单价:20000
3. 总收入:320000


继承是多态得以实现的基础。从字面上理解,多态就是一种类型(都是Car类型)表现出多种状态(宝马汽车的名称是BMW,售价是300000;奇瑞汽车的名称是CheryQQ,售价是2000)。将一个方法调用同这个方法所属的主体(也就是对象或类)关联起来叫做绑定,分前期绑定和后期绑定两种。下面解释一下它们的定义:

1. 前期绑定:在程序运行之前进行绑定,由编译器和连接程序实现,又叫做静态绑定。比如static方法和final方法,注意,这里也包括private方法,因为它是隐式final的。
2. 后期绑定:在运行时根据对象的类型进行绑定,由方法调用机制实现,因此又叫做动态绑定,或者运行时绑定。除了前期绑定外的所有方法都属于后期绑定。


多态就是在后期绑定这种机制上实现的。多态给我们带来的好处是消除了类之间的耦合关系,使程序更容易扩展。比如在上例中,新增加一种类型汽车的销售,只需要让新定义的类继承Car类并实现它的所有方法,而无需对原有代码做任何修改,CarShop类的sellCar(Car car)方法就可以处理新的车型了。新增代码如下:
Java代码 复制代码

1. // 桑塔纳汽车
2. class Santana implements Car {
3. public String getName() {
4. return "Santana";
5. }
6.
7. public int getPrice() {
8. return 80000;
9. }
10. }

// 桑塔纳汽车
class Santana implements Car {
public String getName() {
return "Santana";
}

public int getPrice() {
return 80000;
}
}



重载和重写

重载和重写都是针对方法的概念,在弄清楚这两个概念之前,我们先来了解一下什么叫方法的型构。型构就是指方法的组成结构,具体包括方法的名称和参数,涵盖参数的数量、类型以及出现的顺序,但是不包括方法的返回值类型,访问权限修饰符,以及abstract、static、final等修饰符。比如下面两个就是具有相同型构的方法:
Java代码 复制代码

1. public void method(int i, String s) {
2. // do something
3. }
4.
5. public String method(int i, String s) {
6. // do something
7. }

public void method(int i, String s) {
// do something
}

public String method(int i, String s) {
// do something
}


而这两个就是具有不同型构的方法:
Java代码 复制代码

1. public void method(int i, String s) {
2. // do something
3. }
4.
5. public void method(String s, int i) {
6. // do something
7. }

public void method(int i, String s) {
// do something
}

public void method(String s, int i) {
// do something
}


了解完型构的概念后我们再来看看重载和重写,请看它们的定义:

* 重写,英文名是override,是指在继承情况下,子类中定义了与其基类中方法具有相同型构的新方法,就叫做子类把基类的方法重载了。这是实现多态必须的步骤。
* 重载,英文名是overload,是指在同一个类中定义了一个以上具有相同名称,但是型构不同的方法。在同一个类中,是不允许定义多于一个的具有相同型构的方法的。


我们来考虑一个有趣的问题:构造器可以被重载吗?答案当然是可以的,我们在实际的编程中也经常这么做。实际上构造器也是一个方法,构造器名就是方法名,构造器参数就是方法参数,而它的返回值就是新创建的类的实例。但是构造器却不可以被子类重写,因为子类无法定义与基类具有相同型构的构造器。

标签:

js读取excel文件

<script>
function readThis(){
var tempStr = "";
var filePath= document.all.upfile.value;
var oXL = new ActiveXObject("Excel.application");
var oWB = oXL.Workbooks.open(filePath);
oWB.worksheets(1).select();
var oSheet = oWB.ActiveSheet;
try{
for(var i=2;i<46;i++){
if(oSheet.Cells(i,2).value =="null" || oSheet.Cells(i,3).value =="null" )
break;
var a = oSheet.Cells(i,2).value.toString()=="undefined"?"":oSheet.Cells(i,2).value;
tempStr+=(" "+oSheet.Cells(i,2).value+" "+oSheet.Cells(i,3).value+" "+oSheet.Cells(i,4).value+" "+oSheet.Cells(i,5).value+" "+oSheet.Cells(i,6).value+"\n");
}
}

catch(e){
//alert(e);
document.all.txtArea.value = tempStr;
}

document.all.txtArea.value = tempStr; oXL.Quit();
CollectGarbage();
}
</script>

<html>
<input type="file" id="upfile" />
<input type="button" onclick="readThis();" value="读取"><br>
<textarea id="txtArea" cols=50 rows=10></textarea>
</html>

标签:

2008年8月16日星期六

JQuery 选择器使用

jQuery的选择器可谓异常强大,没有什么DOM里的任何数据能逃出它的掌心,这点是我非常喜欢的,
以前获取NODE要用getElementById,getElementsByTag,非常繁琐,用jQuery,很简单的代码就能实现
下面是对jQuery的选择器使用的总结,不妥之处,敬请斧正.

我把jQuery的选择器选择的方式分5类:

1.DOM方式
$('#id1')
//返回id为id1的TAG,类型:jQuery对象,以下省略

$('#id1 p')
$('#id1>p')
//返回id为id1的TAG下所有的p

能区别 $('#id1 #id2 #id3') 和 $('#id1,#id2,#id3') 的区别吗?

$('#id1,#id2,#id3')
//返回id为#id1下的#id2下的#id3的TAG

$('#id1,#id2,#id3')
//返回id为id1,id2,id3的TAG的群组

2.CSS方式

$('.style')
//返回样式为style的TAG

$('div.style')
//返回样式为style的div

$('.style1,.style2,.style3')
//返回样式为style1,style2,style3的群组

3.属性方式

$('[attribute]')
//返回所有拥有attribute属性的所有tag

$('[attribute=value]')//返回属性attribute值为value的所有tag
$('[attribute!=value]')//返回属性attribute值不为value的所有tag
$('[attribute^=value]')//返回属性attribute值以value开头的所有tag
$('[attribute$=value]')//返回属性attribute值以value结尾的所有tag
$('[attribute*=value]')//返回属性attribute值包含value的所有tag

还可有群组选择
$('[attribute1=value1],[attribute2=value2],[attribute3=value3]')

4.表单'伪'类

形似CSS里的伪类 a:hover 所以就叫表单'伪'类,一己之见

$(':input') //返回所有的input、textarea、select、button
$(':button') //返回所有type为button的表单
其他类似的还有:':text',':password',':radio',':checkbox',':reset',':submit',':file'

$(':disabled') //返回所有的禁用的表单,其实也可以通过属性方式选择
其他类似的还有:':enabled',':checked',':selected'


5."伪伪类"过滤
严格说不应分一类,因为单用这不一定选不出所需的tag(表单类除外)
"伪伪类"过滤对基本方式选择起到了如虎添翼的作用

$("p:first") //返回所选的第一个p

$("p:first-child")//和$("p:first")不同的是,这里是同级下的第一个p

$("p:last") //返回所选的最后一个p
$("p:not(.ok)") //返回样式不是ok的所有的p ,not()中的参数支持以上四种选择方式
$("#id1:parent") //返回id为id1的tag的父节点

标签:

DWR 框架-中级dwr.xml配置

发现一个dwr教程:http://wiki.javascud.org/display/dwrcn/Home
dwr.xml文件如下

<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: dwr -->
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">

<dwr>

<!-- init is only needed if you are extending DWR -->
<init>
<creator id="..." class="..."/>
<converter id="..." class="..."/>
</init>
<allow>
<!>

<create javascript="listService" creator="spring">
<param name="beanName" value="listService" />
<include method="findSubindustryByParent" />
<include method="findAllCitiesByProvince" />
<include method="getIndustries" />
</create>

<!-- create标签用来配置你想要暴露给dwr在页面调用的java类,listServic即为home.dong.ListSerive.
DWR在应用启动时将ListService转化为名为 listService.js的js文件供页面调用。
而creator属性用来配置dwrj应该如何初始化该类的实力以转化成js文件,creator的值有new和spring两种(还有其他如none,scripted等,具体可参看官方文档,说的也很明白(本人暂且只使用了这两种方式)。
很显然,当cteator='new'时dwr会使用java new关键字产生该类实例,然后转化成js文件。而creator='spring'时当然就是由sping容器IOC注入该类实例。所以有下面的<prama>参数也是用配合creator的。
如creator='new'时,对应的<param name="class" value="aaa.bbb.CCC">这样dwr会知道这是一个aaa.bbb.CCC的类,会使用new来创建并转化为js文件,相应的如果creator="spring" 则对应的<param name="beanName" value="someCCC">,dwr创建js文件时就不会new了,而是有spring注入进来的。
<include> 标签很简单,只要把该类中你想要使用的方法填写到里面就行了,这样在你浏览http://localhost:8080/yourPrj/dwr/interface/myClass.js时MyClass类中所有的方法都在可以看见,但是只有你在<include>标签中配置过的那些方法可以使用,也就是没有红色的warning的。


-->

<convert match="com.bomeiti.entity.UI.Industry"
converter="bean">
<param name="include" value="id,description"></param>
</convert>

<!--

<convert>标签使用来转化类的,也就是实体类了,这里需要指明该类的全名(包括包名),<param>用来配置该类中那些属性是可见的。其他没什么难的了,

-->


</allow>

<signatures>
<![CDATA[
import java.util.Map;
import org.apache.struts2.validators.DWRValidator;

DWRValidator.doPost(String, String, Map<String, String>);
]]>
</signatures>
<!--

<signarures>中用来配置莫些具有复杂参数的方法 如listService.getIndustries(Industry ind);此时页面调用时应先组装industry 数据,然后调用


-->

</dwr>

标签:

DWR ajax开发框架-初级配置

首先到:http://directwebremoting.org/下载dwr.jar文件。把它放到你的webapp的WEB-INF/lib目录下.需要把下面的代码加到WEB-INF/web.xml文件中:
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR Servlet</display-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

在WEB-INF目录下的web.xml旁边创建一个dwr.xml文件:
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="JDate">
<param name="class" value="java.util.Date"/>
</create>
<create creator="new" javascript="Demo">
<param name="class" value="your.java.Bean"/>
</create>
</allow>
</dwr>

假设项目名为DwrPrj,部署项目到tomcat 并启动 访问一下网址:
http://localhost:8080/DwrPrj/dwr/
就会看到 暴露出来可供调用的类 ,点击进入便可看到该类的各种方法。

标签: