一、  JavaScript

1、判断输入0-1之间的小数

function checkPower(power)

{

  var str = power.value;

  var reg

=

/(^[1]$)|(^[1]\.[0]{1,2}$)|(^[0]\.[1-9][0-9]{0,1}$)|(^[0]\.[0-9][1-9]$)/;

        if(!reg.test(str))

        {

                alert('权重必须为大于0小于或等于1的小数!');

                power.focus();

                return false;

        }

        return true;

}

2、判断校验输入的是否是以逗号分隔的的数字

形式如:0.34,0.43,0.23 的js

function cursorCheck(obj)          {

                  var str = obj.value;

                  var cursor = getCurror(obj); //光标位置

                var cs = window.event.keyCode; //光标中包含的字符ASII码

               

                if(cursor==0)

                {

                        if(cs==44||cs==46)

                        {

                                return false;

                        }

                }

                else

                {

                        var c = str.substring(cursor-1,cursor);

                        if((c=='.'||c==',')&&(cs==44||cs==46))

                        {

                                return false;

                        }                       

                        if(cs==46)

                        {

                                var t = str.substring(0,cursor);

                                var m = t.substring(t.lastIndexOf(',')+1);

                                if(m.indexOf('.')>-1)

                                {

                                        return false;

                                }

                        }

                }

                return true;

          }

3、js为table新添加一行

var detailT = document.all("myDivTable");                                                               

        var newRow = detailT.insertRow();            

        var cell0 = newRow.insertCell(0);

        cell0.width = "50";

        cell0.align = "center";

        var chbx = "<input style='width:16px' type='checkbox' name='chkbox' value='"

                //+achieveKind.split("|")[0]

                +achieveKind         +","+costUpperValue+","+costLowerValue+","+choujinKind+","+choujinValue+"," + document.all.relationId.value + "'/>";

        cell0.innerHTML = chbx;

        var cell1 = newRow.insertCell(1);

        cell1.width = "82px";

        cell1.align = "center";

        cell1.innerText = achieveName;

        var cell4 = newRow.insertCell(2);

        cell4.width = "135px";

        cell4.align = "center";                                         

        cell4.innerHTML = costUpper;

        var cell4 = newRow.insertCell(3);

        cell4.width = "135px";

        cell4.align = "center";                                          

        cell4.innerHTML = costLower;

        var cell4 = newRow.insertCell(4);

        cell4.width = "122px";

        cell4.align = "center";               

        if (numberOrFormula[1].checked)//公式

        {

                cell4.title = document.all.relationId.options[document.all.relationId.selectedIndex].text;

        }

        cell4.innerHTML = choujinText;

4、日期格式限定

SimpleDateFormat format = new SimpleDateFormat();

    format.applyPattern("yyyy-MM-dd");

    String endDateStr = format.format(new Date());

    String starDateStr = endDateStr.substring(0,8)+"01";

5、js保留小数点后2位

targetScore.toFixed(2);

6、定义锚点

<a name='anchor'>&#160;</a>     

 <a href='anchor'</a>

7、url传递乱码问题

function replaceStr(str)

{

   str = str.replace(/%/g,"%25");

   str = str.replace(/&/g,"%26");

    str = str.replace(/\+/g,"%2B");

    return str;

}

8、js判断某一路径下文件是否存在

var fso;

fso=new ActiveXObject("Scripting.FileSystemObject");

if(!fso.FileExists(file[i].value))

9、file标签,文本域不能输入

contentEditable='false'

10、       js代码动态执行eval

eval("var mydate = new Date();");

eval可以将字符串生成语句执行,和SQL的exec()类似。

eval的使用场合是什么呢?有时候我们预先不知道要执行什么语句,只有当条件和参数给时才知道执行什么语句,这时候eval就派上用场了。举个例子:

我们要做一个function(),功能是输入网页中两个个对象的名称,然后程序就将这两个对象的值联接起来输出。

function output(a,b)

{

var tmpa,tmpb;

tmpa=document.all.a.value;

tmpb=document.all.b.value;

document.write(tmpa+tmpb);

}

output('input1','input2');

这样你执行的时候就会提示错误“document.all.a不是对象”以及“document.all.b不是对象”。原来javascript把a和b当成对象名称了,怎样能让javascript把a里面的值作为对象名称呢?这时候就要用eval了,把代码改成这样:

function output(a,b)

{

var tmpa,tmpb;

tmpa=eval("document.all."+a+".value");

tmpb=eval("document.all."+b+".value");

document.write(tmpa+tmpb);

}

output('input1','input2');

这样javascript就会先取出a,b的值,然后和前面的document.all.以及后面的.value组合运行,于是就可以

顺利取出input1和input2的值,我们的目的达到了。

11、       div样式

<div style="position:absolute; width:220; height:120; top:70; left:470" >

div 在固定位置显示

12、       table样式

<fieldSet style="width:650px;text-align:left;font-family: Verdana;padding:5px;">

        <legend><font style="text-align:center;font-family:arial;font-weight:bold">基本信息</font></legend>

 

 

13、       弹模态窗口

window.showModalDialog('storeInfo.html',window,'dialogHeight:300px;dialogWidth:500px;center:yes');

14、       Frameset设置

<html>

<head>

<title>

test frame

</title>

</head>

<frameset rows="270,*" border="10">

        <frameset cols="20%,*">

                <frame name="query1">

                <frame name="query2">

        </frameset>

        <frameset rows=40%,*%>

                        <frameset cols="50%,50%" >

                                <frame name="list1">

                                <frame name="list2">

                        </frameset>

                                <frame name="deatil">

</frameset>

</html>

15、       js  boolean分析

定义变量  var tab;不赋值  tab为undefined;

Boolean 表达式

一个值为 true 或者 false 的表达式。如果需要,非 Boolean 表达式也可以被转换为 Boolean 值,但是要遵循下列规则:

所有的对象都被当作 true。

当且仅当字符串为空时,该字符串被当作 false。

null 和 undefined 被当作 false。

当且仅当数字为零时,该数字被当作 false。

16、       刷新页面

document.location.replace =当前页面location更新

17、       删除dom元素

document.getElementById("calendarBt1").removeNode(true);

18、       js 中typeof() 函数的用法

typeof 运算符把类型信息当作字符串返回。typeof 返回值有六种可能: "number," "string," "boolean," "object," "function," 和 "undefined."

function delTheLine(){

        document.all['myform'].reset();

}

function test(){

        var myArray =new Array();

        var inputObj = document.getElementById('te');

        var str ='thisisstring';

        alert(' the type of(myArray) is  '+typeof(myArray));

        alert(' the type of(inputObj) is  '+typeof(inputObj));

        alert(' the type of(str) is '+typeof(str));

        alert(' the type of(str) is '+typeof(str/1));

        alert(' the type of(1==2) '+typeof(1==2));

        alert(' the type of(delTheLine)' +typeof (delTheLine));

19、       数组添加,数组内元素连接

rolesArray.push(options[i].value);

rolesArray.join("~");

20、       刷新父页面

window.οnunlοad=function(){

        if(opener!=undefined){

                opener.refresh();

        }

}

21、       Js操作文本域内容连接(dom的使用)

function doHighLight(obj)

        {

                var code = obj.value;

                obj.value = "";

                var factors = document.getElementById("factor");

            var xx      = new CLASS_HIGHLIGHT(code,factors);

            var expSpan = document.createElement("SPAN");

                expSpan.innerHTML = xx.HighLight();       

                obj.appendChild(expSpan);

        }

22、       根据子页面的大小改变父页面的大小

parent.document.body.style.height = document.body.scrollHeight+1000;

23、       js等待与重复执行

例如:tttt=setTimeout('northsnow()',1000);

clearTimeout(tttt);

或者:

tttt=setInterval('northsnow()',1000);

clearInteval(tttt);

24、       js为页面元素添加属性、方法

添加属性:

document.getElementById("comment").setAttribute("readOnly","readonly");

document.getElementById("comment").removeAttribute("readOnly");

添加方法:

 img.attachEvent('onclick',show);

 其中img为页面对象。

25、       iframe 自适应高度

parent.document.all("框架ID名").style.height=document.body.scrollHeight;

parent.document.all("框架ID名").style.width=document.body.scrollWidth;

详细出处参考:http://www.jb51.net/article/15780.htm

26、       动态执行标签onclick事件

var funStr = document.getElementById("faultId");

        funStr.click();

二、  CSS样式

1、readOnly

{

border:1px solid #eeeeee;

}

2、ellipsis

{

overflow:hidden;white-space:nowrap;text-overflow:ellipsis;

}

三、  Jsp

1、获取文件绝对路径

${pageContext.request.contextPath}

2、打印、预览

<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0 id=wb name=wb width=0></OBJECT>    html自带的

wb.execwb(7,1);预览

window.print();打印

3、table 列数据换行

style="word-break: break-all; word-wrap:break-word;"

4、jsp传递中文出乱码解决方案

templateName = new String(request.getParameter("templateName").getBytes("ISO-8859-1"),"GBK");

5、jsp标签对象添加方法

oPopup.document.body.attachEvent("oncontextmenu",function(){return false});

6、读文件

BufferedReader log = (BufferedReader) request.getAttribute("log");

    char[] b = new char[2];

    StringBuffer s = new StringBuffer(200);

    String i = "";

    while ((i = log.readLine()) != null)

    {

        out.write(i);

        out.write("</br>");

    }

    log.close();

7、当前页面屏蔽右键

<BODY οncοntextmenu="return false;" οnclick="listMenu.style.visibility = 'hidden';">

8、右键菜单显示

function showMenu()

    {

        var listMenu = document.getElementById("listMenu");

            var rightedge = document.body.clientWidth-event.clientX;

            var bottomedge = document.body.clientHeight-event.clientY;

            if(rightedge < listMenu.offsetWidth)

                listMenu.style.left = document.body.scrollLeft + event.clientX - listMenu.offsetWidth;

            else

                listMenu.style.left = document.body.scrollLeft + event.clientX;

            if (bottomedge < listMenu.offsetHeight)

                listMenu.style.top = document.body.scrollTop + event.clientY - listMenu.offsetHeight;

            else

                listMenu.style.top = document.body.scrollTop + event.clientY;

        listMenu.style.visibility = "visible";

        listMenu.style.display="block";

    }

    Listmenu 为div

四、  Java

1、获得系统字符集

System.out.println("System.getProperty("file.encoding"));

2、数据格式化

NumberFormat nf = new DecimalFormat("0.00");

 nf.format(str);

不只可以转化为double类型,还可以是其他形式

3、创建文件

File file = new File(System.getProperty("java.io.tmpdir"), filename);

System.getProperty("java.io.tmpdir")获得发布图片文件路径    

本机为 D:\Tomcat 5.0\temp\jfreechart-24660.png

4、Java调用存储过程

1、创建CallableStatement        

2、赋值

 CallableStatement pst = null;

 sql_SltChkp.append("{call svc_state_audit_p(?,?,?,?,?,sysdate,?,?,?)}");

pst = conn.prepareCall(sql_SltChkp.toString());

      pst.setString(1, cityCode);

      pst.setString(2, dealerID);

      pst.registerOutParameter(3, java.sql.Types.INTEGER);

      pst.registerOutParameter(4, java.sql.Types.VARCHAR);

      pst.executeQuery();

      os_Code = String.valueOf(pst.getInt(12));

      os_Msg = pst.getString(13);

5、编写标签

1、标签java文件

2、标签配置文件

3jsp 路径

java:

package com.neusoft.crm.product.common.taglibs;

import javax.servlet.jsp.JspException;

import javax.servlet.jsp.tagext.TagSupport;

import com.neusoft.tdframework.common.GlobalParameters;

import com.neusoft.tdframework.common.data.ParamObjectCollection;

import com.neusoft.tdframework.common.data.ParamObject;

import com.neusoft.tdframework.log.SysLog;

public class BaseSelectTag extends TagSupport {

        public BaseSelectTag() {

                super();

        }

        private String tagName = null;// 下拉列表的名字

        private String selectFlag = null;// 是否有”请选择“一项

        private String indiscriminating = null;// 是否将“请选择“改为其它的文本,如果为"true"改为"不区分";如果是"1"改为"全省";如果是"2"改为"全部";

        private ParamObjectCollection selectColl = null;// 选择字段

        private String selectvalue = null;// 显示项

        private String selectType = null;

        private String fixlength; // 固定长度

        private String  // onclick的响应方法

        private String onchange; // onchange的响应方法

        private String disabled; // 不能改变

        private String isAcceptServiceKind; // 是否受理缴费的服务类型

        public int doEndTag() throws JspException {

                try {

                        pageContext.getOut().write(getSelectXML());

                } catch (Exception e) {

                        e.printStackTrace();

                }

                return super.doEndTag();

        }

        public int doStartTag() throws JspException {

                return super.doStartTag();

        }

        private synchronized String getSelectXML() {

                StringBuffer buf = new StringBuffer();

                buf.append("<SELECT name='" + tagName + "'");

                if (fixlength != null && !fixlength.trim().equals("")) {

                        buf.append(" style='width:" + fixlength + "'");

                }

                if (onclick != null && !onclick.trim().equals("")) {

                        buf.append("  + onclick + "'");

                }

                if (onchange != null && !onchange.trim().equals("")) {

                        buf.append(" οnchange='" + onchange + "'");

                }

                if (disabled != null && !disabled.trim().equals("")) {

                        buf.append(" disabled='" + disabled + "'");

                }

                buf.append("> \n");

                try {

                        if (selectFlag.equals("true")) {

                                if ("true".equals(indiscriminating)) {

                                        buf

                                                        .append("<option value='-1'>\n<caption>不区分</caption>\n</option>");

                                } else if ("1".equals(indiscriminating)) {

                                        buf

                                                        .append("<option value=''>\n<caption>全省</caption>\n</option>");

                                } else if ("2".equals(indiscriminating)) {

                                        buf

                                                        .append("<option value=''>\n<caption>全部</caption>\n</option>");

                                } else {

                                        buf

                                                        .append("<option value=''>\n<caption>请选择</caption>\n</option>");

                                }

                        }

                        if (isAcceptServiceKind != null

                                        && isAcceptServiceKind.equals("true")) {

                                buf

                                                .append("<option value='15'>\n<caption>CDMA1X业务</caption>\n</option>");

                        }

                        if (selectColl == null) {

                                buf

                                                .append("<option><value></value><caption></caption></option>");

                        } else {

                                for (int i = 0; i < selectColl.getRowCount(); i++) {

                                        ParamObject vo = (ParamObject) selectColl.getElement(i);

                                        if (selectvalue != null && selectvalue.length() != 0

                                                        && selectvalue.equals(vo.getId())) {

                                                buf.append(" <option value='" + vo.getId()

                                                                + "' selected> \n");

                                                buf.append("     <caption>" + vo.getName()

                                                                + "</caption> \n");

                                                buf.append(" </option> \n");

                                                continue;

                                        }

                                        buf.append("<option value=");

                                        buf.append(vo.getId());

                                        buf.append(">\n");

                                        buf.append("<caption>");

                                        buf.append(vo.getName());

                                        buf.append("</caption>\n");

                                        buf.append("</option>\n");

                                }

                                buf.append("</SELECT> \n");

                        }

                } catch (Exception e) {

                        SysLog.writeLogs("point", GlobalParameters.ERROR, "getItemInfoXml"

                                        + e.getMessage());

                }

 

                return buf.toString();

        }

 

        /**

         * @return Returns the selectColl.

         */

        public ParamObjectCollection getSelectColl() {

                return selectColl;

        }

 

        /**

         * @param selectColl

         *            The selectColl to set.

         */

        public void setSelectColl(ParamObjectCollection selectColl) {

                this.selectColl = selectColl;

        }

 

        /**

         * @return Returns the selectFlag.

         */

        public String getSelectFlag() {

                return selectFlag;

        }

 

        /**

         * @param selectFlag

         *            The selectFlag to set.

         */

        public void setSelectFlag(String selectFlag) {

                this.selectFlag = selectFlag;

        }

 

        /**

         * @return Returns the selectvalue.

         */

        public String getSelectvalue() {

                return selectvalue;

        }

 

        /**

         * @param selectvalue

         *            The selectvalue to set.

         */

        public void setSelectvalue(String selectvalue) {

                this.selectvalue = selectvalue;

        }

 

        /**

         * @return Returns the tagName.

         */

        public String getTagName() {

                return tagName;

        }

 

        /**

         * @param tagName

         *            The tagName to set.

         */

        public void setTagName(String tagName) {

                this.tagName = tagName;

        }

        /**

         * @return Returns the selectType.

         */

        public String getSelectType() {

                return selectType;

        }

        /**

         * @param selectType

         *            The selectType to set.

         */

        public void setSelectType(String selectType) {

                this.selectType = selectType;

        }

        public String getFixlength() {

                return fixlength;

        }

        public void setFixlength(String fixlength) {

                this.fixlength = fixlength;

        }

        public String getOnchange() {

                return onchange;

        }

        public void setOnchange(String onchange) {

                this.onchange = onchange;

        }

        public String getOnclick() {

                return onclick;

        }

        public void setOnclick(String  {

                this.onclick = onclick;

        }

        public String getDisabled() {

                return disabled;

        }

        public void setDisabled(String disabled) {

                this.disabled = disabled;

        }

        public String getIsAcceptServiceKind() {

                return isAcceptServiceKind;

        }

        public void setIsAcceptServiceKind(String isAcceptServiceKind) {

                this.isAcceptServiceKind = isAcceptServiceKind;

        }

        /**

         * @return the indiscriminating

         */

        public String getIndiscriminating() {

                return indiscriminating;

        }

        /**

         * @param indiscriminating

         *            the indiscriminating to set

         */

        public void setIndiscriminating(String indiscriminating) {

                this.indiscriminating = indiscriminating;

        }

}

2、配置文件

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE taglib

  PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"

  "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

<taglib>

        <tlibversion>1.0</tlibversion>

        <jspversion>1.1</jspversion>

        <shortname>om</shortname>

        <!-- add by zhaofan begin-->

        <tag>

                <name>SelectTag</name>

            <tagclass>com.neusoft.crm.product.common.taglibs.BaseSelectTag</tagclass>

                <bodycontent>empty</bodycontent>

                <info>SelectTag</info>               

            <attribute>

                        <name>selectFlag</name>

                        <required>true</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>

        <attribute>

                <name>indiscriminating</name>

                <required>false</required>

                <rtexprvalue>true</rtexprvalue>

        </attribute>

            <attribute>

                        <name>selectColl</name>

                        <required>true</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>

                <attribute>

                        <name>selectvalue</name>

                        <required>true</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>

                <attribute>

                        <name>tagName</name>

                        <required>true</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>       

            <attribute>

                        <name>fixlength</name>

                        <required>false</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>

                <attribute>

                        <name>onclick</name>

                        <required>false</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>       

                <attribute>

                        <name>onchange</name>

                        <required>false</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>

                <attribute>

                        <name>disabled</name>

                        <required>false</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>

                <attribute>

                        <name>isAcceptServiceKind</name>

                        <required>false</required>

                        <rtexprvalue>true</rtexprvalue>

                </attribute>               

               

        </tag>               

        <!-- add by zhaofan end-->

</taglib>

3jsp 路径

<%@ taglib uri="/WEB-INF/tld/product.tld" prefix="product"%>

6、获得本类的路径

URL url = this.getClass().getResource("");

7、Iterator使用

        for (Iterator iterator = list.iterator(); iterator.hasNext();) {

            EmployeeInfoVO vo = (EmployeeInfoVO) iterator.next();

            str.append("\t<option value='"+vo.getEmployeeId()+"' >");

            str.append(vo.getEmployeeName());

            str.append("</option>\n");

        }

8、Action中实现登陆其他系统(HttpClient)

HttpClient httpClient = new HttpClient();

                 String path = requestd.getContextPath();

                 String url = "http://127.0.0.1:8080/springdeo/dfdf.jsp";

                 //post请求

                 PostMethod postMethod = new PostMethod(url);

                 //填入各个表单域的值

                 NameValuePair[] data = {

                    new NameValuePair("ID", "11"),

                    new NameValuePair("mtg", "0"),

                    new NameValuePair("haveCookie", "0"),

                    new NameValuePair("backID", "30"),

                    new NameValuePair("psw", "password")

                 };

                 //将表单的值放入postMethod中

                 postMethod.setRequestBody(data);

                 //执行postMethod

                 int statusCode = 0;

                  try {

                   statusCode = httpClient.executeMethod(postMethod);

                  } catch (HttpException e) {

                   e.printStackTrace();

                  } catch (IOException e) {

                   e.printStackTrace();

                  }

                  //HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发

                  if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {

                          //从头中取出转向的地址

                          Header locationHeader = postMethod.getResponseHeader("location");

                          String location = null;

                          if (locationHeader != null) {

                                location = locationHeader.getValue();

                                System.out.println("The page was redirected to:" + location);

                          }else {

                                    System.err.println("Location field value is null.");

                           }

                           return mapping.findForward("query");

                  }

                  else {

                      String str = "";try {

                       str = postMethod.getResponseBodyAsString();

                         } catch (IOException e) {

                               e.printStackTrace();

                         }        

                         System.out.println(str);

                  }

                  postMethod.releaseConnection()

9、Action中读xml文件并将信息写到jsp页面

DocumentBuilderFactory factory = DocumentBuilderFactory

                    .newInstance();

            DocumentBuilder builder = factory.newDocumentBuilder();

            URL url = this.getClass().getResource("");

            String path = url.getFile().substring(0,

                    url.getFile().indexOf("WEB-INF"));

            String xmlFilePath = path + "WEB-INF/classes/log4j.xml";

            Document document = builder.parse(new File(xmlFilePath));

            String filePath = null;

            Element rootElement = document.getDocumentElement();

            /*获得标签列表*/

            NodeList list = rootElement.getElementsByTagName("appender");

            int lengh = list.getLength();

            for (int i = 0; i < lengh; i++)

            {

                Element  el =(Element)list.item(i);

                String name = el.getAttribute("name");

                /*循环标签、选择自己要处理*/

                if("FILE_DEBUG_DAILY".equals(name))

                {

                    NodeList nl = el.getElementsByTagName("param");

                   

                    int le = nl.getLength();

                    for (int j = 0; j < le; j++)

                    {

                        Element  eln =(Element)nl.item(j);

                        if("File".equals(eln.getAttribute("name")))

                        {

                            /*获得值*/

                            filePath = eln.getAttribute("value");

                        }

                    }

                }

            }

            BufferedReader bf  = null;

            if(year.equals(todayDate)||"".equals(year))

            {

                file = new File(filePath);

                if(file.exists())

                {

                    bf = new BufferedReader(new FileReader(filePath));

                }else

                {

                    StringReader b = new  StringReader("日志文件不存在"); 

                    bf = new BufferedReader(b);

                }

            }else

            {

                file = new File(filePath+"."+year);

                if(file.exists())

                {

                    bf = new BufferedReader(new FileReader(filePath+"."+year));

                }else

                {

                    StringReader b = new  StringReader("日志文件不存在"); 

                    bf = new BufferedReader(b);

                }

            }

            servletWrapper.getRequest().setAttribute("log", bf);

-------------------------------转到三jsp-6

10、       写文件

int i=0;

        byte[] chrBuffer = new byte[10]; //缓冲\r

        try

        {

            FileInputStream bf = new FileInputStream("D:\\4433.txt");

            FileOutputStream bfo = new FileOutputStream("D:\\ee44");

            while ((i=bf.read(chrBuffer))!=-1)

            {

                bfo.write(chrBuffer,0,i);

            }

        }

11、       Jndi

    <bean id="pms_dataSource"

       class="org.springframework.jndi.JndiObjectFactoryBean">

       <property name="jndiName">

           <value>java:comp/env/jdbc/pmsframework</value>

       </property>

    </bean>

12、       获得web.xml下的配置信息

getServlet().getServletConfig().getInitParameter(

                GlobalParameters.ENCODING)

13、       读取类型为properties的配置文件

ResourceBundle rb = ResourceBundle.getBundle("mail");// 配置文件名称

           String mailServer = rb.getString("mailServer");

           String from = rb.getString("from");

           String userName = rb.getString("userName");

           String password = rb.getString("password");

14、       Java处理excel

ByteArrayOutputStream outs = new ByteArrayOutputStream();

/**

     *<p>Description:生成带初始化数据的excel</p>

     *<p>Remark:</p>

     *@paramtargetVO

     *@return

     *@throwsServiceException

     */

    public String createExcel(InputStream ins,OutputStream outs,RdVO rdVO)

            throws ServiceException

    {

            changeWorkbookByStream(ins,outs);

             try

             {

             WritableWorkbook book = null;

             book = this.wwbook;

             //设置格式

             jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,###");

             jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf);

             wcfN.setBorder(Border.ALL,BorderLineStyle.THIN);

             wcfN.setVerticalAlignment(VerticalAlignment.CENTRE);

             //获得第一个工作表对象

//             isheets = book.getNumberOfSheets();

//             //循环取得处理sheet数据

//             for(int j = 0;j<isheets;j++){

//                 WritableSheet rs = (WritableSheet)book.getSheet(j);

//                

//                 labeltemp = new Label(0, 0, String.valueOf(22222222),wcfN );

//                 ((WritableSheet) rs).addCell(labeltemp);

//             }

             List list= initDAO.getHistoryData(rdVO);

             int length = list.size();

             //循环取得处理sheet数据

             for(int j = 0;j<length;j++){

                 RdVO vo = (RdVO)list.get(j);

                 sheetId = vo.getSheetId();

                 cellRow = vo.getCellRow();

                 cellColumn = vo.getCellColumn();

                 rpData = vo.getRpData();

                 WritableSheet rs = (WritableSheet)book.getSheet(Integer.parseInt(sheetId));

                 labeltemp = new Label(Integer.parseInt(cellRow), Integer.parseInt(cellColumn), String.valueOf(rpData),wcfN );

                 ((WritableSheet) rs).addCell(labeltemp);

              

             }

             book.write();

             //关闭book,释放资源

             book.close();

             rwbook.close();

             }catch(Exception e){      

                 errorMsg = e.getMessage();

                 //errorMsg += "  错误在行 :"+rowTemp+" 列:"+colTemp;

                 System.out.println("出错了啊!!"+errorMsg);

                 System.out.println(e);

                 e.printStackTrace();

                 returnthis.errorMsg;

             }

             returnthis.errorMsg;

        }

15、   打war包

D:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\nmbp>jar -cvf nmbp.war *

16、   Web应用获得文件绝对路径

/**

     *获取指定xml的绝对路径.

     *@paramsourcePath

     *@return绝对路径

     */

    private  String getXmlPath(String sourcePath)

    {

String path = this.getClass().getClassLoader().getResource("").getPath()+"com/neusoft/nmbp/common/socket/xml/"+sourcePath;

       String newFullPath = null;

       try {

            newFullPath=java.net.URLDecoder.decode(path.toString(),"UTF-8");

       } catch (UnsupportedEncodingException e) {

           // TODO Auto-generated catch block

           e.printStackTrace();

       }

       return newFullPath;

}

17、   读属性文件

/*静态代码块,加载属性文件pms.properties*/

    static {

        InputStream inputStream = NmbpConstant.class.getResourceAsStream("/pms.properties");

        nmbpProperties = new Properties();

        try {

            nmbpProperties.load(inputStream);

            inputStream.close();

        }

        catch (IOException e) {

            SysLog.writeExceptionLogs(NmbpConstant.NMBP_APPNAME,

                    GlobalParameters.ERROR, "获取系统属性文件异常:", e);

        }

    }