Archive for 09月, 2008
Published by
admin on
09月 23, 2008
在项目中经常会碰到这样的问题,使用时间戳.记录每个状态点的时间,为了保证统一,均取数据库服务器当前时间.由于数据库持久层采用hibernate,代码如下:
/**
*
* @return 获取数据库服务器时间(通过hibernate获取)
*/
public Date getSysDate(){
return (Date)this.getHibernateTemplate().execute(new
HibernateCallback() {
public Object doInHibernate(Session session) throws SQLException, HibernateException {
Date sysdate =null;
SQLQuery query = session.createSQLQuery(”select sysdate CRTDATE from dual”);
query.addScalar(”CRTDATE”, new org.hibernate.type.TimestampType());
List children = query.list();
sysdate = (Date) children.iterator().next();
releaseSession(session);
return sysdate;
}
}
);
}
Published by
admin on
09月 16, 2008
Lotusscript:
Function GetParameter(paramName As String, queryString As String) As String
Dim startpos,endpos,skiplen As Integer
queryString = queryString + “&” +paramName+”=”+”&”
paramName= Ucase(”&”+paramName+”=”)
skiplen = Len(paramName)
startpos = Instr(Ucase(queryString),paramName)+skiplen
endpos=Instr(startpos,queryString,”&”)
GetParameter=Mid(queryString,startpos,endpos-startpos)
End Function
调用方式如:
tempstr=GetParameter(”selstring”,doc.Query_String(0))
Read the rest of this entry »
Published by
admin on
09月 9, 2008
最近在项目中碰到这样个问题.项目框架ssh,页面使用struts2的标签显示,显示时因有部分字段是字典表.那就需把字典表翻译成对应汉字显示.思考后觉得在po中重新定义1新字段:papertypestr,然后生成get方法.在get方法中进行翻译,是对整体改动量,相对来说最少的.当然struts2标签中也有标签用于专门翻译字段的.
那现在就存在个问题.dao方法如何从spring中获取,如何取才能对系统性能消耗最少.代码如下:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class SpringtUtil {
private static SpringtUtil instance = new SpringtUtil();
private static ApplicationContext context;
public static final String spring_context_configfile = “Spring_xml”;
Read the rest of this entry »
Published by
admin on
09月 9, 2008
Spring框架将DI模式发挥到了极至,因此,系统里面用Spring管理的Bean相互之间的获取是非常方便的,只要使用者提供一个setter方法并在配置文件中配置该属性就可以。
但是,对于系统中非Spring框架管理的类,如果需要获取Spring管理的类,或者,程序中需要动态的根据Be
an的id来获取Bean实例,不可能事先为该类提供所有需要的Bean属性的setter方法,在类似这样的情况下,
获取Spring框架管理的类实例的方法有多种,现在简单总结如下:
方法一:在初始化时保存ApplicationContext对象
代码:
ApplicationContext ac = new FileSystemXmlApplicationContext(”applicationContext.xml”);
ac.getBean(”beanId”);
说明:
这种方式适用于采用Spring框架的独立应用程序,需要程序通过配置文件手工初始化Spring的情况。
方法二:通过Spring提供的工具类获取ApplicationContext对象
代码:
Read the rest of this entry »
Published by
admin on
09月 2, 2008
在web开发中,特别是查询界面时经常会判断是否输入、选择了条件.如果条件很多,那写js代码也很烦的..通过js代码优化处理下。可以很方便判断用户是否输入、选择了条件:
代码如下:
function searchinterbar(){
//表单校验
var strflag=”0″;
fm=document.forms[0] //只检测一个form,如果是多个可以改变判断条件
for(i=0;i<fm.length;i++)
{
//检测判断条件,根据类型不同可以修改
if(fm[i].tagName.toUpperCase()==”INPUT” && fm[i].type.toUpperCase()==”TEXT” && fm[i].value==”"){
//判断input 是否输入
Read the rest of this entry »
Published by
admin on
09月 2, 2008
1. 检查一段字符串是否全由数字组成
—————————————
<script language=”Javascript”><!–
function checkNum(str){return str.match(/\D/)==null}
alert(checkNum(”1232142141″))
alert(checkNum(”123214214a1″))
// –></script>
2. 怎么判断是否是字符
—————————————
if (/[^\x00-\xff]/g.test(s)) alert(”含有汉字”);
else alert(”全是字符”);
3. 怎么判断是否含有汉字
Read the rest of this entry »
Published by
admin on
09月 2, 2008
<script language=”JavaScript”>
<!–
function Request(strName)
{
var strHref = “www.abc.com/index.htm?a=1&b=1&c=测试测试”;
var intPos = strHref.indexOf(”?”);
var strRight = strHref.substr(intPos + 1);
var arrTmp = strRight.split(”&”);
for(var i = 0; i < arrTmp.length; i++)
{
var arrTemp = arrTmp[i].split(”=”);
if(arrTemp[0].toUpperCase() == strName.toUpperCase()) return arrTemp[1];
}
return “”;
}
Read the rest of this entry »
Published by
admin on
09月 1, 2008
用Sruts2时控制台打印了如下警告,谁知道具体是怎么回事啊。怎么可以避免这个警告。
2008-1-6 22:08:45 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
警告: No configuration found for the specified action: ‘user/Add.html’ in namespace: ‘/user’. Form action defaulting to ‘action’ attribute’s literal value.
配置文件:
<?xml version=”1.0″ encoding=”UTF-8″ ?>
<!DOCTYPE struts PUBLIC
“-//Apache Software Foundation//DTD Struts Configuration 2.0//EN”
“http://struts.apache.org/dtds/struts-2.0.dtd”>
Read the rest of this entry »
Published by
admin on
09月 1, 2008
使用sitemesh后。
发现很多页面上的功能都不能用了比如说一个二级联动的下拉列表 只能显示前一个下拉选框,后一个选框却不见了,通过ie看原码 结果html只有一半。
3个配置的xml文件 其中 decorator.xml和web.xml都是通过官网实例修改路径并没有大的改动,sitemesh.xml没有设置但因该是系统使用默认设置。左思右想不得其解,经过网上查找答案后思考.
在使用sitemesh过程中,我的装饰器都能正常装饰文件了,我在decorator.xml中定义了2个装饰器 都是一个main.jsp,一个.panel.jsp 其中main.jsp装饰整个user_admin目录 jsp文件也正确放入了decorators目录下 3个配置文件内容如下
decorator.xml内容如下:
/user_admin/*
/test/*
web.xml内容如下
Read the rest of this entry »