随笔-124  评论-49  文章-56  trackbacks-0
 

 Calendar   g=Calendar.getInstance();  
  g.add(Calendar.YEAR,1);  
  SimpleDateFormat   s=new   SimpleDateFormat("yyyy-MM-dd   HH-mm-ss",Locale.US);  
  String   d=s.format(g.getTime());  
  System.out.println(d);


System.currentTimeMillis();
以毫秒为单位返回当前时间

java.util.Calendar

posted @ 2009-11-29 21:28 junly 阅读(175) | 评论 (0)编辑 收藏
event.getValue() instanceof ActionForm 返回true或false
instanceof判断是否属于此类型
value instanceof Date
posted @ 2009-11-29 21:27 junly 阅读(196) | 评论 (0)编辑 收藏
配置tomcat的连接池
修改context.xml
<Context reloadable="true">
 <WatchedResource>WEB-INF/web.xml</WatchedResource>
 <Resource name="jdbc/oracleds" auth="Container"
 type="javax.sql.DataSource"
 maxActive="100" maxldle="30" maxWait="10000"
 username="scott" password="tiger"
 driverClassName="oracle.jdbc.OracleDriver"
 url="jdbc:oracle:thin:@192.168.1.20:1521:ora9" />
</Context>
posted @ 2009-11-29 21:27 junly 阅读(210) | 评论 (0)编辑 收藏
日期格式化
Date currentTime = new Date();
SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String strCurrentTime=HMFromat.format(currentTime);
posted @ 2009-11-29 21:26 junly 阅读(204) | 评论 (0)编辑 收藏

java.lang.Class
在类加载时,java虚拟机会自动创建相应的class对象
1.获取class对象
Class c=Class.froName("c");
2.解析属性信息
Field[] fs=c.getDeclaredFields();
for(Field f:fs){
   System.out.println("属性:"+f.toString());
   System.out.println("数据类型:"+f.getType());
   System.out.println("属性名:"+f.getName());
   int mod=f.getModifeers();
   System.out.println("属性修饰符:"+Modifier.toString(mod));
}
3.解析方法信息
Method[] ms=c.getDeclaredMethods();
for(Method m:ms){
   System.out.println("方法:"+m.toString());
   System.out.println("方法名:"+m.getName());
   int mod=f.getModifeers();
   System.out.println("方法修饰符:"+Modifier.toString(mod));
   Class pts[] = m.getParameterTypes();//得到参数列表
   m.getReturnType();//得到返回值类型
}
4.解析构造方法
Constructor[]  cs=c.getDeclaredConstructors();
for(Constructor con:cs){
   System.out.println("构造方法:"+con.toString());
   System.out.println("方法名:"+con.getName());
   System.out.println("方法修饰符:"+Modifier.toString(mod));
   Class pts[] = m.getParameterTypes();//得到参数列表
   m.getReturnType();//得到返回值类型
}
5.解析当前类类型的父类
Class superClass=c.getSuperclass();
6.解析当前类实现的接口
Class[] interfaces=c.getInterfaces();
for(Class cl:interfaces){
   System.out.println(cl.toString());
}
7.解析当前包
Package p=c.getPackage();
---------------------------------------------------------------

1.直接操作对象属性
User u=new User();
Class c=u.getClass();//同Class.forName("p2.User");
Field f=c.getField(fieldName);
Object fv=f.get(u);//得到对象u实例对应f属性的值
f.set(u,value);设置u对象f属性的值为value
2.调用对象成员方法
Class[] argTypes={String.class,int.class};
//上行等同Class[] argTypes=new Class[]{String.class,int.class};
Object[] args=new Object[]{"王五",99};

Class c-u.getClass();
Method m=c.getMethod(methodName,argTypes);
Object result=m.invoke(u,args);
System.out.println(result);
3.调用类成员方法
Class c=Class.forName("className");
Method m=c.getMethod(methodName,argTypes);
Object result=m.invoke(null,args);//没有对象,所以指定为null
---------------------------------------------------------------
获取class对象
*针对引用数据类型
1.调用静态方法Class.forName()
Class.forName("p1.User");
2.调用Object类中定义的getClass()方法
User u=new User();
Class c=u.getClass();
3.使用.class表达式
Class c1=String.class;
Class c2=p1.User.class;
*针对基本数据类型及void
1.使用.class表达式
Class c1=int.class;
Class c2=double.class;
Class c3=void.class;
2.调用相应封装类的.Type属性
Class c1=Integer.TYPE;
Class c2=Double.TYPE;
Class c3=Void.TYPE;
----------------------------------------------
java.lang.reflect.Field
1.获取Field对类(Class类提供)
public Field[] getDeclaredFields()//当前类的所有属性,不包括父类
public Field getDeclaredField(String name)//当前类指定属性,不包括父类
public Field[] getFields()//当前类所有public的属性,包括父类
public Field getField(String name)//当前类指定的public属性,包括父类
2.Field类主要成员方法
public Object get(Object obj)
pbulic void set(Object obj,Object value)
public xxx getXxx(Object obj)
public void setXxx(Object obj,xxx x)//xxx为基本数据类型
public String getName()
public int getModifiers()//当前属性的修饰符
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
返回当前属性前面的注释
public String toString()
public boolean equals(Object obj)
------------------------------------------------------------------------
java.lang.reflect.Method
1.获取Method对类(Class类提供)
public Method[] getDeclaredMethods()//当前类的所有方法,不包括父类
public Method getDeclaredMethod(String name,Class<?> parameterTypes)//当前类指定方法,不包括父类
public Method[] getMethods()//当前类所有public的方法,包括父类
public Method getMethod(String name)//当前类指定的public方法,包括父类
2.Method类主要成员方法
public Object invoke(Object obj,Object args)****
public String getName()
public Class<?>[] getParameterTypes()
public int getModifiers()//当前属性的修饰符
public Class<?> getReturnType()
public Class<?>[] getExceptionTypes()
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
返回当前属性前面的注释
public String toString()
public boolean equals(Object obj)
-----------------------------------------------------------
java.lang.reflect.Modifier
1.获取Modifier对象
public int getModifieers()
2.Modifier类方法
public static boolean isPublic(int mod)
public static boolean isPrivate(int mod)

--------------------------------------------------------------
java.lang.reflect.Constructor
public T newInstance(Object initargs)

Class c=Class.forName("p1.Person");
Class[] argTypes={String.class,int.class};//参数列表
Constructor cons=c.getConstructor(argTypes);
Object obj=cons.newInstance("中国",5000);

调用无参构造方法
cons=c.getconstructor();
obj=constructor.newInstance();
obj=c.newInstance();
----------------------------------------------------------------
java.lang.reflect.Array

class类方法
public Class<?> getComponentType()//返回数组对象的数据类型

posted @ 2009-11-29 21:24 junly 阅读(178) | 评论 (0)编辑 收藏

Tomcat 配置文件修改
修改server.xml
<Connector port="8080" protocol="HTTP/1.1" maxThereads="150"
connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>
目的:解决Get方法传参的中文乱码问题
修改Context.xml
<Context>修改成<Context reloadable="true">
目的:当WEB应用中的文件或web.xml 文件修改后Tomcat服务器会自动加载当前的web应用。避免重新启动Tomcat.
<Context reloadable="false">产品阶段不要改为true,改为 false
修改tomcat-users.xml
<?xml version='1.0' encoding='uft-8'?>
<tomcat-users>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="liuwei" password="liuwei"
 roles="admin,manager"/>
</tomcat-users>

web错误处理
401错误
404错误
500错误
解决方案:订制错误信息页面,设置web.xml文件
<error-page>
  <error-code>404</error-code>
  <location>/error404.html</location>
</error-page>
<error-page>
  <error-code>500</error-code>
  <location>/error500.html</location>
</error-page>

posted @ 2009-11-29 21:23 junly 阅读(1006) | 评论 (0)编辑 收藏
 

1、设置SQL Server服务器:

1-1、“SQL Server 2005 服务”中停止服务“SQL Server SQLEXPRESS)”(默认是启动状态)

1-2、“SQL Server 2005 网络配置” MSSQLSERVER 的协议”,启动“TCP/IP”(默认是禁用状态),然后双击“TCP/IP”进入属性设置,在“IP 地址”里,确认“IPAll

中的“TCP 端口”为1433

1-3、“SQL Server 2005 服务”中启动服务“SQL Server MSSQLSERVER )”(默认是停止状态)

1-4、关闭“SQL Server Configuration Manager”(此时可以启动“SQL Server Management Studio”,并用帐户sa、密码123登录,SQL Server服务器设置正确的话应该能登录成功)

2、导入jar包:

打开Test的“Properties Java Build Path Libraries Add External JARs ,选择下载好的连接驱动包“sqljdbc.jar”,然后点击“OK”确定

3如果你以前用JDBC连接SQL Server 2000的话就要注意了

SQL Server 2000 中加载驱动和URL路径的语句是

“com.microsoft.jdbc.sqlserver.SQLServerDriver”
jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=JSPTest”

SQL Server 2005 中加载驱动和URL的语句则为

“com.microsoft.sqlserver.jdbc.SQLServerDriver”

jdbc:sqlserver://localhost:1433; DatabaseName=JSPTest”

注意两者的差异
posted @ 2009-11-29 21:22 junly 阅读(185) | 评论 (0)编辑 收藏

 

Set temp=new HashSet();
Set entries 
= temp.entrySet();
  
for (Iterator iter = entries.iterator(); iter.hasNext();) {
   Map.Entry entry 
= (Map.Entry) iter.next();
   ACL acl 
= (ACL)entry.getValue();
  }
posted @ 2009-11-29 21:20 junly 阅读(173) | 评论 (0)编辑 收藏

管理连接对象
Modle:biz,dao,entity
数据源接口:javax.sql.DataSource
得到
javax.namming.Context接口的lookup()方法
java:comp/env/jdbc/books


1 Tomcat的conf/context.xml(Tomcat5.5以前配在server.xml中<host>标签中)
 <context>
  <Resource name="jdbc/books"//JNDI名称
       auth="Container"//连接池由谁管理(container完全由容器管理/application由程序管理)
       type="javax.sql.DataSource"//数据源类型
       maxActive="100"//最大连接
       maxIdle="30"//最大空闲
       maxWait="10000"//单位毫秒,最大等待,无限等待值设为-1
       username="sa"
       password="accp"
       driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
       url="jdbc:sqlserver://localhost:1433;databaseName=food"
        />
 </context>

2 加数库据驱动jar
-5.5以前
 TomCat/comm/lib
-5.5以后
 TomCat/lib目录下
 

3 编写代码
 *javax.naming.context;
 *javax.naming.InitialContext;
 Connection conn;
 Statement stmt;
 ResultSet rs;
 try{
  Context ctx=new InitialContext();
  DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/books");
  conn=ds.getConnection();
  stmt=conn.createStatement();
  rs=stmt.executeQuery(sql);
 }catch(){}

posted @ 2009-11-29 21:19 junly 阅读(310) | 评论 (0)编辑 收藏

1 输入/输出流
           字节流      字符流
 输入流  InputStream    Reader
 输出流  OutputStream   Writer
2 字节流和处理流
------------------------------------------------------------------------
3 InputStream 向程序中输入数据
InputStream---FileInputStream
InputStream---StringBufferInputStream
InputStream---ObjectInputStream
基本方法
-读取一个字节并以整数的形式返回
-如果返回-1已到输入流的末尾
int read() throws IOException
-读取一系列字节并存储到一个数组buffer
int read(byte[] buffer) throws IOException
-读取length个字节并存到一个字节数组buffer
int read(byte[] buffer,int offset[数组的那个下标开始存],int lenght) throws IOException
-关闭流
void close() throws IOException
-------------------------------------------------------------------------------
4 outputStream 输出数据
OutputStream---FileOutputStream
OutputStream---ObjectOutputStream
-向输出流中写一个字节数据
void write(int b)throws IOException
-将一个字节类型的数组中的数据写入输出流
void write(byte[] b)throws IOException
-将一个字节类型的数组中的从指定位置off开始的len个字节写入到输出流
void write(byte[] b,int off,int len)throws IOException
-关闭流
void close()throws IOException
-将输出流中缓冲的数据全部写出到目的地(重要:先flush再close)
void flush() throws IOException
-----------------------------------------------------------------------------------
5 Reader/Writer
---------------------------------------------------
6 FileInputStream/OutputStream
long num=0;
try{
 FileInputStream in=new FileInputStream("d:\\test.txt");
 FileOutputStream out=new FileOutputStream("d:/test1.text");
 while(int b=in.read()!=-1){
  out.write(b);
 }
 in.close();
 out.close();
}catch(){}
7 FileReader/FileWriter
  FileReader fr=null;
  FileWriter fw=null;
  int c=0;
  try{
 fr=new FileReader ("d:\\test.java");
 fw=new FileWriter ("d:/test1.java");
 while((c=fr.read)!=-1){
    System.out.print((char)c);
    fw.write(c);
 }
      fr.close();
      fw.close();
  }
 8 缓冲流
 常用构造方法
 BufferedReader(Reader in)
 BufferedReader(Reader in,int sz)
 BufferedWreter(Writer out)
 BufferedWreter(Writer out,int sz)
 BufferedInputStream(InputStream in)
 BufferedInputStream(InputStream in,int size)
 BufferedOutputStream(OutputStream out)
 BufferedOutputStream(OutputStream out,int size)
 *BufferedReader提供了readLine方法用于读取一行字符串
 *BufferedWreter提供了newLine用于写入一个行分隔符
 *可以使用flush方法将输出到缓冲流的数据在内存中清空立刻写入硬盘
try{
    FileInputStream fis=new FileInputStream("d:\\share\\HelloWorld.java");
    BufferedInputStream bis=new BufferedInputStream (fis);
    bis.mark(100);从第100开始读
}

try{
     BufferedWriter bw=new BufferedWriter (new FileWriter("d:\\test.txt"));
     BufferedReader br=new BufferedReader(new FileReader("d:\\test.txt"));
     String s=null;
     for(int i=0;i<=100;i++){
 s=String.valueOf(Math.random());
 bw.write(s);
        bw.newLine();//写一个换行符
     }
     bw.flush();//清空缓存写入文件
     while((s=br.readLine())!=null){
 System.out.println(s);
     }
     bw.close();
     br.close();
}
9 转换流
  InputStreamReader/OutputStreamWriter
  用于字节数据到字符数据之间的转换
  InputStreamReader 需要和 InputStream "套接"
  OutputStreamWriter 需要和 OutputStream "套接"
  InputStream isr=new InputStreamReader(System.in,"ISO8859-1");

try{
  OutputStreamWriter osw=new OutputStreamWriter (new FileOutputStream("d:\\test.txt"));
  osw.write("ssssssssssssssss");
  osw.close();
  osw=new OutputStreamWriter(new FileOutputStream("d:\\test.txt",true),"ISO8859-1");//true是指在原来的基础上添加
  osw.write("ddddddddddddddddddd");
  osw.close();
}

InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();

10 流据流,存储和读取java原始类型
DataInputStream(InputStream in)/DataOutputStream(OutputStream out)
boolean readBoolean()
double readDouble()
String readUTF()

11 PrintStream / PrintWriter
printStream ps=null;
try{
   FileOutputStream fos=new FileOutStream("d:\\test.txt");
   ps=new PrintStream(fos);
}
if(ps!=null){
   System.setOut(ps);
}
int ln=0;
for(char c=0;c<=60000;c++){
   System.out.print(c+" ");
   if(ln++>=100){
 System.out.println();
 ln=0;
   }
}

12 ObjectInputStream/ObjectOutputStream
对象读写必须序列化,transient关键字表示该必性不被序列化
class t implements Serializable{
  int i=10;
  transient int j=9;
  double d=2.3;
}

T t=new T();
FileOutputStream fos=new FileOutputStream ();
ObjectOutputStream oos=new ObjectOutputStream (fos);
oos.writeObject(t);
oos.flush();
oos.close();
13 Externalizable接口
方法:
   void readExternal(ObjectInput in)
   void writeExternal(ObjectOutput out)

posted @ 2009-11-29 21:18 junly 阅读(192) | 评论 (0)编辑 收藏
仅列出标题
共18页: First 上一页 7 8 9 10 11 12 13 14 15 下一页 Last