java技术博客

jsp博客
数据加载中……

2008年10月25日

jquery的ajax应用

//定义用户名校验的方法
function verify(){
    
//首先测试一下页面的按钮按下,可以调用这个方法
    //使用javascript的alert方法,显示一个探出提示框
    //alert("按钮被点击了!!!");

    
//1.获取文本框中的内容
    //document.getElementById("userName");  dom的方式
    //Jquery的查找节点的方式,参数中#加上id属性值可以找到一个节点。
    //jquery的方法返回的都是jquery的对象,可以继续在上面执行其他的jquery方法
    var jqueryObj = $("#userName");
    
//获取节点的值
    var userName = jqueryObj.val();
    
//alert(userName);

    
//2.将文本框中的数据发送给服务器段的servelt
    //使用jquery的XMLHTTPrequest对象get请求的封装
    $.get("AJAXServer?name=" + userName,null,callback);


}


//回调函数
function callback(data) {
//    alert("服务器段的数据回来了!!");
    //3.接收服务器端返回的数据
//
    alert(data);
    //4.将服务器段返回的数据动态的显示在页面上
    //找到保存结果信息的节点
    var resultObj = $("#result");
    
//动态的改变页面中div节点中的内容
    resultObj.html(data);
    alert(
"");
}

posted @ 2009-01-17 16:35 郭兴华 阅读(329) | 评论 (0)编辑 收藏
上海交通大学java视频教程共31讲

上海交通大学java视频教程共31讲
If you are interested in java, you can spend time learning about it

posted @ 2009-01-12 22:17 郭兴华 阅读(576) | 评论 (0)编辑 收藏
*.class 如何打包

先放下吧

posted @ 2008-11-13 09:12 郭兴华 阅读(163) | 评论 (0)编辑 收藏
java中的printf

public class TestPrintf{
    
public static void main(String args[]){
        System.out.printf(
"%+8.3f",3.14);    
        System.out.println();            
        System.out.printf(
"%+-8.3f\n",3.14);
        System.out.printf(
"%08.3f\n",3.14);
        System.out.printf(
"%(8.3f\n",-3.14);
        System.out.printf(
"%,f\n",2356.34);
        System.out.printf(
"%x\n",0x4a3b);
        System.out.printf(
"%#x\n",0x4a3b);        
        System.out.println(
"------------");    
        System.out.printf(
"你好:%s,%3d岁,工资%-7.2f\n","张三",38,15000.00);        
        System.out.printf(
"你好:%1$s,%2$3d岁,%2$#x岁\n","张三",38);        
        System.out.printf(
"%3d,%#<x",38);
    }
    
}

posted @ 2008-11-13 09:09 郭兴华 阅读(364) | 评论 (0)编辑 收藏
java中的集合

     摘要: Integer[] a = {3,25,12,79,48};         System.out.println(a);         System.out.println(Arrays.toStrin...  阅读全文

posted @ 2008-11-13 09:07 郭兴华 阅读(268) | 评论 (0)编辑 收藏
Arraylist

 

/**
 * 测试数组列表的使用
 
*/

 
import java.util.ArrayList;

public class ArrayListTest
{
    
public static void main(String[] args)
    
{
        ArrayList list 
= new ArrayList();
        list.add(
new Student("Tom","20020410"));
        list.add(
new Student("Jack","20020411"));
        list.add(
new Student("Rose","20020412"));

        
for(int i = 0; i < list.size(); i++)
        
{
            System.out.println((Student)list.get(i));
        }

    }

}


class Student
{
    
private String strName = "";//学生姓名
    private String strNumber = "";//学号
    private String strSex = "";//性别
    private String strBirthday = "";//出生年月
    private String strSpeciality = "";//专业
    private String strAddress = "";//地址

    
public Student(String name, String number)
    
{
        strName 
= name;
        strNumber 
= number;
    }


    
public String getStudentName()
    
{
        
return strName;
    }


    
public String getStudentNumber()
    
{
        
return strNumber;
    }


    
public void setStudentSex(String sex)
    
{
        strSex 
= sex;
    }


    
public String getStudentSex()
    
{
        
return strSex;
    }


    
public String getStudentBirthday()
        
{
        
return strBirthday;
    }


    
public void setStudentBirthday(String birthday)
    
{
        strBirthday 
= birthday;
    }


    
public String getStudentSpeciality()
    
{
        
return strSpeciality;
    }


    
public void setStudentSpeciality(String speciality)
    
{
        strSpeciality 
= speciality;
    }


    
public String getStudentAddress()
    
{
        
return strAddress;
    }


    
public void setStudentAddress(String address)
    
{
        strAddress 
= address;
    }


    
public String toString()
    
{
        String information 
= "学生姓名=" + strName + ", 学号=" + strNumber;  
        
if!strSex.equals("") )
            information 
+= ", 性别=" + strSex;
        
if!strBirthday.equals(""))
            information 
+= ", 出生年月=" + strBirthday;
        
if!strSpeciality.equals("") )
            information 
+= ", 专业=" + strSpeciality;
        
if!strAddress.equals("") )
            information 
+= ", 籍贯=" + strAddress;
        
return information;
    }

}

posted @ 2008-11-07 16:34 郭兴华 阅读(210) | 评论 (0)编辑 收藏
java的动态多态

/**
 * 通过本程序的测试,主要学习抽象类及子类,抽象方法的实现
 * 动态绑定,多态
 
*/

 
import java.text.NumberFormat;

public class AbstractTest
{
    
public static void main(String[] args)
    
{
        Person[] p 
= new Person[2];
        p[
0= new Worker("Jack"1000);
        p[
1= new Student("Tom""Computer");
        
        
for(int i = 0; i < p.length; i++)
        
{
            Person people 
= p[i];
            System.out.println(people.getDescription());
        }

    }

}


/**
 * 抽象类
 
*/

abstract class Person
{
    
private String strName;

    
public Person(String strName)
    
{
        
this.strName = strName;
    }


    
public String getName()
    
{
        
return strName;
    }


    
//抽象方法,返回人的描述
    public abstract String getDescription();
}


/**
 * 工人类,扩展了抽象类,并实现了抽象方法
 
*/

class Worker extends Person
{
    
private double salary;
    
    
public Worker(String strName, double s)
    
{
        
super(strName);
        salary 
= s;
    }

    
    
public String getDescription()
    
{
        NumberFormat formate 
= NumberFormat.getCurrencyInstance();
        
return "the worker with a salary of " + formate.format(salary);
    }

}


/**
 * 学生类,扩展了抽象类,实现了抽象方法
 
*/

class Student extends Person
{
    
private String strMajor;
    
    
public Student(String strName, String strMajor)
    
{
        
super(strName);
        
this.strMajor = strMajor;
    }

    
    
public String getDescription()
    
{
        
return "the student majoring in " + strMajor;
    }

}

posted @ 2008-11-07 16:31 郭兴华 阅读(268) | 评论 (0)编辑 收藏
java中的HashMapTest

     摘要: /** *//**  * 通过这个程序,测试散列映像的存储与遍历,方法的使用  */ import java.util.HashMap; import java.util.Collection; import java.util.Iterator; import java.util.Set; public&nb...  阅读全文

posted @ 2008-11-07 16:12 郭兴华 阅读(319) | 评论 (0)编辑 收藏
java中的treeset

/**
 * 通过这个程序,测试树集的添加元素的无序性与输出的有序性
 
*/

 
import java.util.TreeSet;
import java.util.Iterator;

public class TreeSetTest
{
    
public static void main(String[] args)
    
{
        TreeSet tree 
= new TreeSet();
        tree.add(
"China");
        tree.add(
"America");
        tree.add(
"Japan");
        tree.add(
"Chinese");
        
        Iterator iter 
= tree.iterator();
        
while(iter.hasNext())
        
{
            System.out.println(iter.next());
        }

    }

}

posted @ 2008-11-07 16:10 郭兴华 阅读(495) | 评论 (0)编辑 收藏
java中的treemap

     摘要: /** *//**  * 通过这个程序,测试树映像的使用,表目集合的遍历  */ import java.util.TreeMap; import java.util.Map; import java.util.Iterator; import java.util.Set; public class&...  阅读全文

posted @ 2008-11-07 16:08 郭兴华 阅读(4590) | 评论 (0)编辑 收藏
java中的vector

     摘要: /** *//** *//** *//**  * 我们设计的学生基本类  */ class Student {     private String strName = "";//学生姓名     ...  阅读全文

posted @ 2008-11-07 16:02 郭兴华 阅读(342) | 评论 (0)编辑 收藏
记录类被实例化的次数

/*01*/public class classNumberDemo 
/*02*/{
/*03*/      public static int objNum=0;
/*04*/      public classNumberDemo()
/*05*/      {
/*06*/          classNumberDemo.objNum++;
/*07*/      }

/*08*/      public void show()
/*09*/      {
/*10*/          System.out.println("the No."+classNumberDemo.objNum);
/*11*/      }

/*12*/      
/*13*/        public static void main(String args[])
/*14*/        {
/*15*/             classNumberDemo p=null;
/*16*/             p=new classNumberDemo();
/*17*/             p.show();
/*18*/             p=new classNumberDemo();
/*19*/             p.show();
/*20*/             p=new classNumberDemo();
/*21*/             p.show();             
/*22*/      }

/*23*/}

posted @ 2008-11-05 22:16 郭兴华 阅读(352) | 评论 (0)编辑 收藏
java编程小实例

/**   2005 Aptech Limited
 *     版权所有
 
*/


/**
 * 该程序测试使用 break 关键字来检测的质数
 * 
@version 1.0, 2005 年 5 月 22 日
 * 
@author Michael
 
*/


public class PrimeNumber {

    
/** 构造方法*/
    PrimeNumber() 
{
    }


     
/**
      * 这是一个 main 方法
      * 
@param args 传递至 main 方法的参数
      
*/


    
public static void main(String[] args) {

    
int number = 29;

    
for (int i = 2; i < number; i++{

        
if (number % i == 0{
        System.out.println(
"不是质数");
        
break;
        }
 else {
            System.out.println(
"它是一个质数");
            
break;
           }

       }

    }

}





/*
 * 2005 Aptech Limited
 * 版权所有
 
*/


/**
 * 此类将输出数组中第二个最大的数字
 * 
@version 1.0, 2005 年 5 月 22 日
 * 
@author Michael
 
*/


public class HighestNumber {

    
/** 构造函数. */
    HighestNumber() 
{
    }


     
/**
      * 这是一个 main 方法
      * 
@param args 传递至 main 方法
      
*/


     
public static void main(String[] args) {


     
int[] array = {43798};
     
int greatest = 0;
     
int secondhighest = 0;

     
for (int i = 1; i < 5; i++{

         
if (greatest < array [i]) {

         secondhighest 
= greatest;
         greatest 
= array[i];

         }
 else {

             
if (secondhighest < array[i]) {

                 secondhighest 
= array[i];
                 }

             }

         }

         System.out.println(
"第二大的数字是: " + secondhighest);

     }

}

posted @ 2008-11-04 07:56 郭兴华 阅读(150) | 评论 (0)编辑 收藏
i++与++i的区别

public class ppDemo
{
    
public static void main(String[] args)
    
{
    
int result=0;
    
int p=2*result++;
    System.out.println(p);
    System.out.println(result);
    result
=0;
    
int y=2*++result;
    System.out.println(result);
    System.out.println(y);
    }

}

posted @ 2008-11-03 14:37 郭兴华 阅读(119) | 评论 (0)编辑 收藏
java静态成员

/*01*/public class static_demo
/*02*/{
/*03*/    public static int i=0;
/*04*/    public int j=0;
/*05*/    public void show()
/*06*/    {
/*07*/    System.out.println(i);
/*08*/    System.out.println(j);
/*09*/    }

/*10*/}

/*11*/
/*12*/class test
/*13*/{
/*14*/    public static void main(String args[])
/*15*/    {
/*16*/    static_demo obj1=new static_demo();
/*17*/    obj1.i=100;
/*18*/        obj1.j=200;
/*19*/        obj1.show();
/*20*/        static_demo obj2=new static_demo();
/*21*/    obj2.show();
/*22*/    }

/*23*/}

posted @ 2008-11-03 14:14 郭兴华 阅读(91) | 评论 (0)编辑 收藏
java中的静态代码段

/*01*/public class static_block
/*02*/{
/*03*/    public String name;
/*04*/    public String sex;
/*05*/    public int    age;
/*06*/  public static_block(String na,String se,int ag)
/*07*/  {
/*08*/      name=na;
/*09*/      sex=se;
/*10*/      age=ag;
/*11*/  }

/*12*/    public void show()
/*13*/    {
/*14*/        System.out.println("Name:"+name);
/*15*/        System.out.println("Sex:"+sex);
/*16*/        System.out.println("Age:"+age);
/*17*/    }

/*18*/    static{
/*19*/          System.out.println("hello block");
/*20*/    }

/*21*/    public static void main(String args[])
/*22*/    { System.out.println("hello main");
/*23*/        static_block pObj=new static_block("zhangsan","male",30);
/*24*/        pObj.show();
/*25*/    }

/*26*/}

posted @ 2008-11-03 08:47 郭兴华 阅读(310) | 评论 (0)编辑 收藏
++i与i++

public class ppDemo{
public static void main(String[] args)
{
int i=0;
result
=1+i++;
System.out.println(i);
System.out.println(result);
i
=0;
result
=1+++i;
System.out.println(i);
System.out.println(result);
}

}

posted @ 2008-10-31 11:57 郭兴华 阅读(101) | 评论 (0)编辑 收藏
java代理模式

package orj.jzkangta.proxydemo02;

public class ComputerMaker implements SaleComputer {

    
public void sale(String type) {
        System.out.println(
"卖出了一台"+type+"电脑");

    }


}



package orj.jzkangta.proxydemo02;

import java.lang.reflect.Proxy;

public class ComputerProxy {
    
public static SaleComputer getComputerMaker(){
        ProxyFunction pf
=new ProxyFunction();
        
return (SaleComputer)Proxy.newProxyInstance(ComputerMaker.class.getClassLoader(), ComputerMaker.class.getInterfaces(), pf);
    }

}





package orj.jzkangta.proxydemo02;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class ProxyFunction implements InvocationHandler {
    
private ComputerMaker cm;
    
    
public void youHui(){
        System.out.println(
"我给你一些优惠。。。");
    }

    
    
public void giveMouse(){
        System.out.println(
"我还要送你一个鼠标。。。 ");
    }

    
public Object invoke(Object arg0, Method arg1, Object[] arg2)
            
throws Throwable {
        String type
=(String)arg2[0];
        
if(type.equals("联想")||type.equals("三星")){
            
if(cm==null){
                cm
=new ComputerMaker();
                youHui();
                giveMouse();
                arg1.invoke(cm, type);
            }

        }
else{
            System.out.println(
"我没有你要的这个牌子的电脑。。。。");
        }

        
return null;
    }


}

package orj.jzkangta.proxydemo02;

public interface SaleComputer {
    
public void sale(String type);
}


package orj.jzkangta.proxydemo02;

public class Test {

    
    
public static void main(String[] args) {
        SaleComputer sc
=ComputerProxy.getComputerMaker();
        
//sc.sale("联想");
        
//sc.sale("三星");
        sc.sale("Dell");

    }


}

posted @ 2008-10-31 07:49 郭兴华 阅读(720) | 评论 (0)编辑 收藏
java中的多态

/*01*/public class overdemo1
/*02*/{
/*03*/    public static void main(String args[])
/*04*/    {
/*05*/    Child c=new Child();
/*06*/        int iResult=c.add(1,2);
/*07*/    double dResult=c.add(1.0,2.0);
/*08*/    System.out.println(iResult);
/*09*/    System.out.println(dResult);
/*10*/    }

/*11*/}

/*12*/
/*13*/class Parent
/*14*/{
/*15*/   public int add(int a, int b)
/*16*/   {
/*17*/       return  a+b;
/*18*/   }

/*19*/}

/*20*/
/*21*/class Child extends Parent
/*22*/{
/*23*/   public double add(double a, double b)
/*24*/   {
/*25*/        return a+b;
/*26*/   }

/*27*/}

posted @ 2008-10-30 14:31 郭兴华 阅读(120) | 评论 (0)编辑 收藏
java方法的重载

/*01*/public class calculator
/*02*/{
/*03*/   public int add(int a, int b)   
/*04*/   {
/*05*/        return a+b;
/*06*/   }

/*07*/   public double add(double a, double b)
/*08*/   {
/*09*/         return a+b;
/*10*/   }

/*11*/   public float add(float a, float b)
/*12*/   {
/*13*/         return a+b;
/*14*/   }

/*15*/   public static void main(String args[])
/*16*/   {
/*17*/          calculator cal=new calculator();
/*18*/          int iResult=cal.add(12,13);
/*19*/          double dResult=cal.add(12.0,13.0);
/*20*/          float  fResult=cal.add(12.0f13.0f);
/*21*/          System.out.println(iResult);
/*22*/          System.out.println(dResult);
/*23*/          System.out.println(fResult);
/*24*/   }

/*25*/}

posted @ 2008-10-30 14:23 郭兴华 阅读(72) | 评论 (0)编辑 收藏
本程序搜索文件中的字

     摘要: /** *//**  (C) 北大青鸟APTECH.  *   版权所有  */ /** *//**  * 本程序导入所需的类.  */ import java.io.File; import java.io.BufferedR...  阅读全文

posted @ 2008-10-30 09:12 郭兴华 阅读(59) | 评论 (0)编辑 收藏
本程序搜索文件中的字

     摘要: /** *//**  (C) 北大青鸟APTECH.  *   版权所有  */ /** *//**  * 本程序导入所需的类.  */ import java.io.File; import java.io.BufferedR...  阅读全文

posted @ 2008-10-30 09:12 郭兴华 阅读(80) | 评论 (0)编辑 收藏
本程序搜索文件中的字

     摘要: /** *//**  (C) 北大青鸟APTECH.  *   版权所有  */ /** *//**  * 本程序导入所需的类.  */ import java.io.File; import java.io.BufferedR...  阅读全文

posted @ 2008-10-30 09:12 郭兴华 阅读(92) | 评论 (0)编辑 收藏
判断一个一个路径是否是目录

/**  
 *   (C) 北大青鸟APTECH.
 *   版权所有
 
*/


/**
 * 本程序导入所需的类.
 
*/

import java.io.File;

/**
 * 本程序演示 File 类的使用.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


class ListDirectory {

/** 存储要搜索的目录名称. */
    String directoryName;

/** 声明一个 File 对象. */
    File fileObj;

/** 
 * 构造方法.
 * 
@param name 是一个字符串
 
*/

    ListDirectory(String name) 
{
       directoryName 
= name;
       fileObj 
= new File(name);
    }


/** 
 * 显示目录和子目录的方法.
 
*/

    
void display() {
       
if (fileObj.isDirectory()) {
          System.out.println(
"目录是 : " + directoryName);
          String[] fileName 
= fileObj.list();

          
for (int ctr = 0; ctr < fileName.length; ctr++{
              File nextFileObj 
= new File(directoryName + "/" + fileName[ctr]);

              
if (nextFileObj.isDirectory()) {
                 System.out.println(fileName[ctr] 
+ " 是一个目录");
              }
 else {
                 System.out.println(fileName[ctr] 
+ " 是一个文件");
              }

          }

        }
 else {
              System.out.println(directoryName 
+ " 不是一个有效目录");
        }

    }

}


/**
 * 本程序测试 ListDirectory 类.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


class DirectoryTest {

/** 
 * 构造方法. 
 
*/

    
protected DirectoryTest() {
    }


/**
 * 这是一个 main 方法.
 * 
@param args 被传递至 main 方法
 
*/

    
public static void main(String[] args) {
        ListDirectory listObj 
= new ListDirectory("java");
        listObj.display();
    }

}

posted @ 2008-10-30 08:09 郭兴华 阅读(1078) | 评论 (0)编辑 收藏
抽象类和方法的用法.

     摘要: /**//* 北大青鸟APTECH  * 版权所有  */ /** *//**  * 这个程序演示抽象类和方法的用法.  * @版本 1.0 2005 年 5 月 20 日  * @author M...  阅读全文

posted @ 2008-10-29 18:52 郭兴华 阅读(206) | 评论 (0)编辑 收藏
java的多态

/*  北大青鸟APTECH.
 *  版权所有
 
*/


/**
 * 这个程序演示动态多态性的用法.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/

abstract class Shape {

    
/** 存储任何形状的长. */
    
protected double length;

    
/** 存储任何形状的宽. */
    
protected double width;

    
/** 
     * 构造方法.
     * 
@param num 传递至构造方法
     * 
@param num1 传递至构造方法
     
*/

    Shape(
final double num , final double num1) {

    
/** 初始化变量. */
        length 
= num;
        width 
= num1;
    }


    
/**
     * 抽象方法.
     * 
@return double 值
     
*/

    
abstract double area();
}


/**
 * 这个类重写父类的方法.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


class Square extends Shape {

    
/** 构造方法.
     *
@param num 传递至构造方法的参数
     *
@param num1 传递至构造方法的参数
     
*/

    Square(
final double num, final double num1) {
        
super(num, num1);
    }


    
/**
     * 计算正方形的面积.
     * @return传递给构造方法的 length
     
*/


    
double area() {
        System.out.println(
"正方形的面积为:" );
        
return length * width;
    }

}


/**
 * 这个类重写父类的方法.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


class Triangle extends Shape {

    
/** 构造方法.
     *
@param num 传递至构造方法的参数
     *
@param num1 传递至构造方法的参数
     
*/

    Triangle(
final double num, final double num1) {
        
super(num, num1);
    }


    
/**
     * 计算三角形的面积.
     *
@return double  传递给构造方法的length
     
*/


    
double area() {
        System.out.println(
"三角形的面积为:" );
        
return (0.5 * length * width);
    }

}


/**
 * 这个类测试对象引用.
 * 
@version 1.0 2005 年 5 月 20 日
 * 
@author Michael
 
*/


public class CalculateArea {

    
/** 构造方法. */
    
protected CalculateArea() {
    }


    
/**
     * 这是 main 方法.
     * 
@param arg 传递至 main 方法的参数
     
*/


    
public static void main(final String[] arg) {
        
// 初始化变量
        Shape fObj;
        Square sqObj 
= new Square(10 , 20);
        Triangle trObj 
= new Triangle(12 , 8);
        fObj 
= sqObj;
        System.out.println(fObj.area());
        fObj 
= trObj;
        System.out.println(fObj.area());
    }

}

posted @ 2008-10-29 07:39 郭兴华 阅读(126) | 评论 (0)编辑 收藏
java数组的Copy

/**
* 测试数组元素拷贝
*/
public class ArrayCopy
{
public static void main(String[] args)
{
ArrayCopy aCopy
= new ArrayCopy();
int[] a = {1, 2, 3, 4, 5};
int[] b = {10,20,30,40,50};
aCopy.copy(a, b);

}

public void copy(int[] from, int[] to)
{
System.out.println(
"第一个数组中的元素");
for (int i = 0; i < from.length; i++)
{
System.out.print(
" " + from[i]);//打印出数组中的每一个元素
}
System.out.println(
"\n");

System.out.println(
"第二个数组中的元素");
for (int i = 0; i < to.length; i++)
{
System.out.print(
" " + to[i]);//打印出数组中的每一个元素
}

System.out.println(
"\n\n将第一个数组拷贝到第二个数组\n");
System.arraycopy(from,
2, to, 0, 3);

System.out.println(
"拷贝完成后第二个数组中的元素");
for (int i = 0; i < to.length; i++)
{
System.out.print(
" " + to[i]);//打印出数组中的每一个元素
}
}
}

输出结果是3 4 5 40 50

posted @ 2008-10-28 10:11 郭兴华 阅读(174) | 评论 (0)编辑 收藏
JDBC连接SQLSERVER

     摘要: <%@page language="java" import="java.util.*,java.sql.*,Oper.*,voo.*" pageEncoding="GBK"%> <table border=1> <tr>     <th>编号</th>...  阅读全文

posted @ 2008-10-26 09:46 郭兴华 阅读(1813) | 评论 (0)编辑 收藏
jsp读取*.TXT

package mypack;
import java.io.*;

public class ReadText{
    
public String getShiGe(){
        
//File f=new File("guoxinghua.txt");
        File f=new File(this.getClass().getResource("guoxinghua.txt").toURI());
        
try{
            FileReader fr
=new FileReader(f);
            BufferedReader buff
=new BufferedReader(fr);//BufferedReader用于读取文本
            String line="";
            
while((line=buff.readLine())!=null)
            
{
                retstr
+line+"<br>";
                }

                buff.close();
                }

            
catch(Exception e)
            
{
                e.printStackTrace();
                
                }

                
                
                
return retstr;
                }

    }



<%@page language="java" import="java.util.*,mypack" page Encoding="GBK"%>
<%
ReadText rt
=new ReadText();
%>
<%=rt.getShiGe()%>

posted @ 2008-10-26 07:20 郭兴华 阅读(753) | 评论 (1)编辑 收藏
java1.5注解(二)


import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class  SuppressWarningsTest
{
    
public static void main(String[] args) 
    
{
        Map
<String,Date> map=new TreeMap<String,Date>();
        map.put(
"hello",new Date());
        System.out.println(map.get(
"hello"));
    }

}





import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class  SuppressWarningsTest2
{
    
public static void main(String[] args) 
    
{
        Map map
=new TreeMap();
        
//Map<String,Date> map=new TreeMap<String,Date>();
        map.put("hello",new Date());
        System.out.println(map.get(
"hello"));
    }

}




import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class  SuppressWarningsTest3
{
    @SuppressWarnings(
"unchecked")
    
public static void main(String[] args) 
    
{
        Map map
=new TreeMap();
        
//Map<String,Date> map=new TreeMap<String,Date>();
        map.put("hello",new Date());
        System.out.println(map.get(
"hello"));
    }

}






import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class DeprecatedTest 
{
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
        
    }

}


class  SuppressWarningsTest2
{
    
public static void main(String[] args) 
    
{
        Map map
=new TreeMap();
        
//Map<String,Date> map=new TreeMap<String,Date>();
        map.put("hello",new Date());
        System.out.println(map.get(
"hello"));
    }

}




import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
class DeprecatedTest 
{
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
        
    }

}


class  SuppressWarningsTest2
{
    @SuppressWarnings(
{"unchecked","deprecation"})
    
public static void main(String[] args) 
    
{
        Map map
=new TreeMap();
        
//Map<String,Date> map=new TreeMap<String,Date>();
        map.put("hello",new Date());
        System.out.println(map.get(
"hello"));
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
    }

}


posted @ 2008-10-26 00:21 郭兴华 阅读(348) | 评论 (0)编辑 收藏
java1.5注解(一)

 

 

由来

减少代码和程序错误的发生
C#中的也有这种情况

对java程序没有直接影响,
内置注解
Override
Deprecated
SuppressWarnings

//对学框架有帮助
通过程序来说明

注意override与overload区别
class OverrideTest2 
{
    @Override
    
public String toString(){
    
return "guoxinghua";
    }

    
public static void main(String[] args) 
    
{
        OverrideTest2 test
=new OverrideTest2();

        System.out.println(test.toString());
    }

}



class OverrideTest3 
{
    
//@Override
    public String ToString(){
    
return "guoxinghua";
    }

    
public static void main(String[] args) 
    
{
        OverrideTest3 test
=new OverrideTest3();

        System.out.println(test.toString());
    }

}


class OverrideTest3 
{
    @Override
    
public String ToString(){
    
return "guoxinghua";
    }

    
public static void main(String[] args) 
    
{
        OverrideTest3 test
=new OverrideTest3();

        System.out.println(test.toString());
    }

}






class DeprecatedTest 
{
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
        
    }

}





class DeprecatedTest 
{
    @Deprecated
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        DeprecatedTest test
=new DeprecatedTest();
        test.doSomething();
        
    }

}








class SubDeprecatedTest extends DeprecatedTest 
{
    @Override
    
public void doSomething(){
    System.out.println(
"guoxinghua");
    }

    
public static void main(String[] args) 
    
{
        SubDeprecatedTest sub
=new SubDeprecatedTest();
        sub.doSomething();
    }

}

posted @ 2008-10-25 22:22 郭兴华 阅读(557) | 评论 (0)编辑 收藏
jsp中使用类




package mypack;
class Student 
{
    
private int age;
    
private String xm;
    
private float mark;
    
public void setAge(int age){
        
this.age=age;
        }

        
public int getAge(){
        
return age;
        }

        
public void setXm(String xm)
    
{
        
this.xm=xm;
        }

        
public String getXm()
    
{
        
return xm;
        }

        
public void setMark(float mark)
    
{
        
this.mark=mark;
        }

        
public float getMark(){
        
return mark;
        }

        

}



package mypack;
class Say 
{
    
public String hello(String xm) 
    
{return "Hello World "+xm;
    }

}






<%@page language="java" import ="java.util.*,mypack.*" pageEncoding="GBK"%>
   <%@import="....."%>//用于多个包的导入
<%!
public int add(int x,int y)
{
return x+y;
}

int a=10;

%>


<%
Student stu
=new Student();
stu.setAge(
29);
stu.setXm(
"guoxinghua");
stu.setMark(
200.0F);
int a=100;
%>
<%Say s=new Say()%>
<%=s.hello(stu.getXm())%>
<%=s.add(10,20)%><%=stu.getAge()%>
<%=stu.getXm()%>
<%=stu.getMark()%>
<%=this.a%>
<%=a%>

<%%>这种是代码段,在这里声明的方法和变量是在局部的
<%!%>这种是声明语句,在这里声明的变量和方法是全局的
 <%=%>这种是表达式

posted @ 2008-10-25 11:55 郭兴华 阅读(226) | 评论 (0)编辑 收藏