0734w-月下竹音

0734是来自家乡的声音

常用链接

统计

最新评论

平时经验总结

1.设置一个按钮为有用或不能用,
 <%
 if(index.intValue()%2==1)
  {
 %>
<input type="button" name="Update" class="kuButton" value='Update' disabled onclick="submitUpdate();return false;">
<input type="button" name="Delete" class="kuButton" value='Delete' disabled onclick="submitDel();return false;"></td>
<%
 }else{
 %>
<input type="button" name="Update" class="kuButton" value='Update' disabled onclick="submitUpdate();return false;">
<input type="button" name="Delete" class="kuButton" value='Delete' disabled onclick="submitDel();return false;"></td>
<%
}
%> 

2.让你一个按钮显示不显示
显示:document.formname.id.style.display="none"
不显示:document.formname.id.style.display="inline"

3.在一个链接中要用到动态的参数,要调用方法,但是传参数时容易出现问题,最好的方式是:
action='<%="artMaintAction.do?method="+ session.getAttribute("method")+"&firstlevel=3&secondlevel=1"%>'


4,当页面提交是为默为的utf-u编码,我们要转换成GB2312才能正确插入到数据库中:
在SEVLETK加上:request.seCharacterEncoding("gb2312")

5.传递表单参数:
String name = new String(request.getParameter("name"));


7.文件操作

~~将一个字符串写到一个指定的文件中,如果该文件不存在,则新建一个文件,并完成写入;如果存在,则用此字符串覆盖原文件的所有内容
import java.io.*;
String str = "print me";
//定义好打印的目标文件名

//取得当前主机存放WEB页面的绝对路径
String hostdir = System.getProperty("user.dir");
//取得当前主机所采用的路径分隔符
String fileBar = System.getProperty("file.separator");
//书写完整的目标文件存放路径
String nameOfFile=hostdir+fileBar+"test.html";

try
//实例化一个文件输出流对象
FileOutputStream afile = new FileOutputStream(nameOfFile);
//将文件输出流,创建一个打印输出流对象
PrintWriter pw = new PrintWriter(afile);
pw.println(str);
//clean up
pw.close();
{}
catch(IOException e)
out.println(e.getMessage());
{}

~~列出指定目录下的文件列表
import java.io.*;
String cdur = System.getProperty("user.dir");
String fileBar = System.getProperty("file.separator");
String mydir =cdur+fileBar+"doc"+fileBar+"jspsky";
File my = new File(mydir);
String d[] = my.list();
int i;
int l=d.length;
for(i=0;i out.print(d[i]);
{}


8.计数器
Integer count = null;
synchronized (application)
count =(Integer) application.getAttribute("d");
if (count ==null)
count =new Integer("0");
count = new Integer(count.intValue()+1);
application.setAttribute("d",count);
{}
out.println(count);
// 首先定义一个整形对象,并初始化为:NULL,
// 取回APPLICATION对像的属性D的值,并强制转化为整形对象,赋给COUNT
// 判断COUNT是否为空,为空时,将O赋给COUNT对象,
// 否则,通过COUNT。INTVALUE()方法,实现COUNT对象加1,并赋值给COUNT
// 最后,将COUNT对象保存在APPLICATION对象的D变量中。

9,在JAVA中
String a[] = { "a", "ab" };
String b[][] = { { "abc", "abcd" }, { "d" } };

10,不能把逻辑直接放在一个类里面方法外面,这是一个很低级的错误,而且会使你找不到错误在哪里。

11,在数组中
String a[] = { "a", "aa" ,"aaa"};
String c[] = { "c", "cc" };
如果a = c 即变成是a[]== { "c", "cc" };
    c = a 即变成是c[]=={ "a", "aa" ,"aaa"};它们不是一个一个的赋值。
   
11,数组能存放原始对象(primitive)和Object对象,容器只能存放Object对象,不过可以使用类将其转换,不过数组的效率比容器高很多。数组是不可变的
 
 
12,n = Math.abs(n)是返回N的决对值]

13,http://java.sun.com/docs/books/tutorial/index.html    THE Java Tutorial

14,Array中Arrays.fill(a9, 1, 3, "World");是把a9中的第二个字符和第三个字符填上world

15,java.util.array类是一组用于数组操作的static方法它有四个基本方法:
Arrays.fill(object, values) , Arrays.sort(), Arrays.equals() , Arrays.binarySearch()[用天排列数组查找对象]
System.arraycopy(fromobject,startnum,toobject,startnum,length)用于数组之间的拷贝
 Arrays.equals(objecta,objectb);返回一个boolen值,这里相等一定指长度相同,而且第一个元素相同
 Arrays.sort(a); 对对象a进行排序,a是数字以小数字放前面,a是字母以A开头a第二,以此类推
int location = Arrays.binarySearch(a, 20);查找a中为20(必须为20不能多不能少)的位置,在查找之前必须用Arrays.sort(a);排序

16.在JAVA数组中:
String[] s1 = { "Hi", "Hi", "Hi", "Hi", "Hi" };
String[] s2 = { "Hi", "Hi", "Hi", "Hi", "Hi" };
String[] s3 = { "Hi", "Hi", "Hi", "11", "" };
Arrays.equals(s1,s2)成立,Arrays.equals(s3,s2)不成立,它是基本内容的比较,相当与s1-s2(中间为减号),返回的是一个大于小于或等于O的数
s2.equals(s3),s2==s3它们是基于对象的比较(内存中比较)


17,返回一个1-100的整数:
static Random r = new Random();
Math.abs(r.nextInt()) % 100;

18,在其它类里面调用静态方法:new testT.TConstraction1(5);只会调用静态类的确定的构造函数,不会调用其它代码:
class testT {
    testT() {System.out.println("TConstraction(..)");}
    public static class TConstraction1 {
        public void atest() {
            System.out.println(" 会执行所有的Constaction代代码");
        }
        public TConstraction1(int i) {
            System.out.println("-static void TConstraction1 i==" + i);
        };
    }
}

19,s.toLowerCase()将s中所有字母转换成小写字母

20,容器分为:collection map
collection分为set ,list.
set里面的值不能重复,ArrayList,hashSet    添加为a.add("test") set会进行排序
MAP是一个链接保存一对对象,也可以转换成Collection     添加为:a.put("test","test2"):

21,list中也能用Collections.fill()静态方法来填充字符,但是必须要在原来里面有值的时候才能填
List list = new ArrayList();
for (int i = 0; i < 10; i++) {
    list.add("");
}
Collections.fill(list, "Hello");



21,ArrayList其实就是一个可变长的数组,它方法也较简单:用add("a")加,用get(i)得到第i个对象

22.collection(list and set)包含以下功能:
exp: collection c= new Arraylist(); collection b= new Arraylist(); String c ="1";
c.add(object c);
c.addAll(collection b);
c.clear();
c.contains(object b);
c.containsAll(collection b);
c.isEmpty();
Iterator iteratora = a.iterator(); while(iteratora.hasNest())
c.remove(object c);
c.removeAll(collection b);
c.size();容器大小
没有get(i)随机取值
LinkedList有addFirst() removeFirst() addLast() removeLast();


23.map有两个方法可以分别打印key and values
System.out.println(mapt1.values());
System.out.println(mapt1.keySet());
也可以直接打印System.out.println(mapt1);
map使用Iterator 必须使用keySet 或values如:Iterator it =map1.keySet.iterator();
map1中可以使用map1.get(object key);
containsKey()包含一个key对象;
containsValues()包含一个值对象;

24,Math.random() * 20
返回一个1-20之间的一个应意随机数,返回的是一个doubel型的,如果想产生在1-20整数使用:
Integer r = new Integer( (int) (Math.random() * 20));

25,SortedMap 比HASHMAP多了几个属性:
map1.firstKey();第一个
map1.lastKey();最后一个
map1.subMap(fromKey,toKey);返回值中包括前者不包括后者
map1.headMap(toKey);返回的值都小于fromKey
map1.tailMap(fromKey);返回的值都大于fromKey

26。HashMap 要用equals()不能判断查询的键是不是与表里面的其它键相等。
equals()具有五个属性:反身,对称,传递,一致,非空

27.取得当前主机的名称:
//取得当前主机存放WEB页面的绝对路径
  String hostdir = System.getProperty("user.dir");
//取得当前主机所采用的路径分隔符
  String fileBar = System.getProperty("file.separator");
//书写完整的目标文件存放路径
  String nameOfFile=hostdir+fileBar+"test.html";      

posted on 2005-12-23 10:55 sparkwu 阅读(142) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: