Java 技术研究 欢迎大家

欢迎大家 来到我的blog , 如果我身边的朋友 有什么不懂可以直接来问我 我会细心的帮助你的. 如果网络上的朋友有什么不懂的 可以加我QQ48187537
posts - 36, comments - 20, trackbacks - 0, articles - 1

置顶随笔

     摘要:   阅读全文

posted @ 2007-08-09 14:13 郑成桥 阅读(93) | 评论 (0)编辑 收藏

2008年8月14日

首先 顺序导入 spring hibernate struts

配置applicationContet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns
="http://www.springframework.org/schema/beans"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    
<bean id="datasource"
         
class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        
<property name="driverClass"
            value
="com.microsoft.jdbc.sqlserver.SQLServerDriver">
        
</property>
        
<property name="jdbcUrl"
            value
="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=blog;SelectMethod=cursor">
        
</property>
        
<property name="user" value="sa"></property>
        
<property name="password" value="sa"></property>
        
<property name="minPoolSize" value="5"></property>
        
<property name="maxPoolSize" value="20"></property>
        
<property name="acquireIncrement" value="5"></property>
    
</bean>
    
<bean id="sessionFactory"
        
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
<property name="dataSource">
            
<ref bean="datasource" />
        
</property>
        
<property name="hibernateProperties">
            
<props>
                
<prop key="hibernate.dialect">
            org.hibernate.dialect.SQLServerDialect 
                
</prop>
                
<prop key="hibernate.show_sql">true</prop>
            
</props>
        
</property>

        
<property name="mappingDirectoryLocations">
            
<list>
               
<value>classpath:/com/zcq/dao</value> 
            
</list>
        
</property>
    
</bean> 
       
<!--  hibernateTemplate 配置 -->
         
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
          
<property name="sessionFactory">
            
<ref bean="sessionFactory" />
          
</property> 
         
</bean>
      
<!-- zcqbb datable -->
         
<bean id="daoimp" class="com.zcq.dao.Test" >
           
<property name="hibernateTemplate" ref="hibernateTemplate" /> 
         
</bean> 
 
</beans> 

然后写接口


然后实现接口
package com.zcq.job.dao;

import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.zcq.job.I.Zcq_I;

public class Zcq_Imp extends HibernateDaoSupport implements Zcq_I {

    
public void show() {
      System.out.println(
"sssssss");
    }

    
public static Zcq_I getApplication(ApplicationContext ctx)
    
{
        
return (Zcq_I)ctx.getBean("daoimp");
    }

}


web.xml 里加入
  <context-param>
    
<param-name>contextConfigLocation</param-name>
    
<param-value>/WEB-INF/applicationContext.xml</param-value>
  
</context-param>
  
<listener>
    
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  
</listener>
  
<filter>
    
<filter-name>CharacterEncodingFilter</filter-name>
    
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    
<init-param>
      
<param-name>encoding</param-name>
      
<param-value>gbk</param-value>
    
</init-param>
    
<init-param>
      
<param-name>forceEncoding</param-name>
      
<param-value>true</param-value>
    
</init-param>
  
</filter>
  
<filter-mapping>
    
<filter-name>CharacterEncodingFilter</filter-name>
    
<url-pattern>/*</url-pattern>
  </filter-mapping>

posted @ 2008-08-14 14:52 郑成桥 阅读(58) | 评论 (0)编辑 收藏

2008年7月1日

import  java.io.*; 
 
public  class  FileOperate  { 
   public  FileOperate()  { 
   } 
 
   /** 
     *  新建目录 
     *  @param  folderPath  String  如  c:/fqf 
     *  @return  boolean 
     */ 
   public  void  newFolder(String  folderPath)  { 
       try  { 
           String  filePath  =  folderPath; 
           filePath  =  filePath.toString(); 
           java.io.File  myFilePath  =  new  java.io.File(filePath); 
           if  (!myFilePath.exists())  { 
               myFilePath.mkdir(); 
           } 
       } 
       catch  (Exception  e)  { 
           System.out.println("新建目录操作出错"); 
           e.printStackTrace(); 
       } 
   } 
 
   /** 
     *  新建文件 
     *  @param  filePathAndName  String  文件路径及名称  如c:/fqf.txt 
     *  @param  fileContent  String  文件内容 
     *  @return  boolean 
     */ 
   public  void  newFile(String  filePathAndName,  String  fileContent)  { 
 
       try  { 
           String  filePath  =  filePathAndName; 
           filePath  =  filePath.toString(); 
           File  myFilePath  =  new  File(filePath); 
           if  (!myFilePath.exists())  { 
               myFilePath.createNewFile(); 
           } 
           FileWriter  resultFile  =  new  FileWriter(myFilePath); 
           PrintWriter  myFile  =  new  PrintWriter(resultFile); 
           String  strContent  =  fileContent; 
           myFile.println(strContent); 
           resultFile.close(); 
 
       } 
       catch  (Exception  e)  { 
           System.out.println("新建目录操作出错"); 
           e.printStackTrace(); 
 
       } 
 
   } 
 
   /** 
     *  删除文件 
     *  @param  filePathAndName  String  文件路径及名称  如c:/fqf.txt 
     *  @param  fileContent  String 
     *  @return  boolean 
     */ 
   public  void  delFile(String  filePathAndName)  { 
       try  { 
           String  filePath  =  filePathAndName; 
           filePath  =  filePath.toString(); 
           java.io.File  myDelFile  =  new  java.io.File(filePath); 
           myDelFile.delete(); 
 
       } 
       catch  (Exception  e)  { 
           System.out.println("删除文件操作出错"); 
           e.printStackTrace(); 
 
       } 
 
   } 
 
   /** 
     *  删除文件夹 
     *  @param  filePathAndName  String  文件夹路径及名称  如c:/fqf 
     *  @param  fileContent  String 
     *  @return  boolean 
     */ 
   public  void  delFolder(String  folderPath)  { 
       try  { 
           delAllFile(folderPath);  //删除完里面所有内容 
           String  filePath  =  folderPath; 
           filePath  =  filePath.toString(); 
           java.io.File  myFilePath  =  new  java.io.File(filePath); 
           myFilePath.delete();  //删除空文件夹 
 
       } 
       catch  (Exception  e)  { 
           System.out.println("删除文件夹操作出错"); 
           e.printStackTrace(); 
 
       } 
 
   } 
 
   /** 
     *  删除文件夹里面的所有文件 
     *  @param  path  String  文件夹路径  如  c:/fqf 
     */ 
   public  void  delAllFile(String  path)  { 
       File  file  =  new  File(path); 
       if  (!file.exists())  { 
           return; 
       } 
       if  (!file.isDirectory())  { 
           return; 
       } 
       String[]  tempList  =  file.list(); 
       File  temp  =  null; 
       for  (int  i  =  0;  i  <  tempList.length;  i++)  { 
           if  (path.endsWith(File.separator))  { 
               temp  =  new  File(path  +  tempList[i]); 
           } 
           else  { 
               temp  =  new  File(path  +  File.separator  +  tempList[i]); 
           } 
           if  (temp.isFile())  { 
               temp.delete(); 
           } 
           if  (temp.isDirectory())  { 
               delAllFile(path+"/"+  tempList[i]);//先删除文件夹里面的文件 
               delFolder(path+"/"+  tempList[i]);//再删除空文件夹 
           } 
       } 
   } 
 
   /** 
     *  复制单个文件 
     *  @param  oldPath  String  原文件路径  如:c:/fqf.txt 
     *  @param  newPath  String  复制后路径  如:f:/fqf.txt 
     *  @return  boolean 
     */ 
   public  void  copyFile(String  oldPath,  String  newPath)  { 
       try  { 
           int  bytesum  =  0; 
           int  byteread  =  0; 
           File  oldfile  =  new  File(oldPath); 
           if  (oldfile.exists())  {  //文件存在时 
               InputStream  inStream  =  new  FileInputStream(oldPath);  //读入原文件 
               FileOutputStream  fs  =  new  FileOutputStream(newPath); 
               byte[]  buffer  =  new  byte[1444]; 
               int  length; 
               while  (  (byteread  =  inStream.read(buffer))  !=  -1)  { 
                   bytesum  +=  byteread;  //字节数  文件大小 
                   System.out.println(bytesum); 
                   fs.write(buffer,  0,  byteread); 
               } 
               inStream.close(); 
           } 
       } 
       catch  (Exception  e)  { 
           System.out.println("复制单个文件操作出错"); 
           e.printStackTrace(); 
 
       } 
 
   } 
 
   /** 
     *  复制整个文件夹内容 
     *  @param  oldPath  String  原文件路径  如:c:/fqf 
     *  @param  newPath  String  复制后路径  如:f:/fqf/ff 
     *  @return  boolean 
     */ 
   public  void  copyFolder(String  oldPath,  String  newPath)  { 
 
       try  { 
           (new  File(newPath)).mkdirs();  //如果文件夹不存在  则建立新文件夹 
           File  a=new  File(oldPath); 
           String[]  file=a.list(); 
           File  temp=null; 
           for  (int  i  =  0;  i  <  file.length;  i++)  { 
               if(oldPath.endsWith(File.separator)){ 
                   temp=new  File(oldPath+file[i]); 
               } 
               else{ 
                   temp=new  File(oldPath+File.separator+file[i]); 
               } 
 
               if(temp.isFile()){ 
                   FileInputStream  input  =  new  FileInputStream(temp); 
                   FileOutputStream  output  =  new  FileOutputStream(newPath  +  "/"  + 
                           (temp.getName()).toString()); 
                   byte[]  b  =  new  byte[1024  *  5]; 
                   int  len; 
                   while  (  (len  =  input.read(b))  !=  -1)  { 
                       output.write(b,  0,  len); 
                   } 
                   output.flush(); 
                   output.close(); 
                   input.close(); 
               } 
               if(temp.isDirectory()){//如果是子文件夹 
                   copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]); 
               } 
           } 
       } 
       catch  (Exception  e)  { 
           System.out.println("复制整个文件夹内容操作出错"); 
           e.printStackTrace(); 
 
       } 
 
   } 
 
   /** 
     *  移动文件到指定目录 
     *  @param  oldPath  String  如:c:/fqf.txt 
     *  @param  newPath  String  如:d:/fqf.txt 
     */ 
   public  void  moveFile(String  oldPath,  String  newPath)  { 
       copyFile(oldPath,  newPath); 
       delFile(oldPath); 
 
   } 
 
   /** 
     *  移动文件到指定目录 
     *  @param  oldPath  String  如:c:/fqf.txt 
     *  @param  newPath  String  如:d:/fqf.txt 
     */ 
   public  void  moveFolder(String  oldPath,  String  newPath)  { 
       copyFolder(oldPath,  newPath); 
       delFolder(oldPath); 
 
   } 
}

posted @ 2008-07-01 16:51 郑成桥 阅读(72) | 评论 (0)编辑 收藏

2008年3月13日

     摘要: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <head>  <html&g...  阅读全文

posted @ 2008-03-13 19:54 郑成桥 阅读(78) | 评论 (0)编辑 收藏

2008年3月5日

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns
="http://www.springframework.org/schema/beans"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">



<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"></property>

 
</bean>

</beans>
import java.util.Date;
import java.util.Locale;

import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestBean {
    
    
public static void main(String[] args) {
        
        ApplicationContext context
=null;
        
        context
=new ClassPathXmlApplicationContext("guojihua.xml");
        Object[] a
=new Object[]{"郑成桥",new Date()};
    System.out.println(context.getMessage(
"user", a,Locale.SIMPLIFIED_CHINESE));
        
    }

}


上面Object[] 里面的user 是国际化里的配置的
user=\u6B22\u8FCE{0},\u7684\u5230\u6765\u73B0\u5728\u662F{1}

如果看不懂 ,  就直接加我的 QQ 问吧...

posted @ 2008-03-05 18:09 郑成桥 阅读(98) | 评论 (0)编辑 收藏

2008年2月24日

Demo1.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="java.awt.*" %>
<%@ page import="java.awt.image.*" %>
<%@ page import="javax.imageio.*" %>
<%!
    Color getRanColor(
int fc,int bc)
    {
        Random random
=new Random();
        
if(fc>255) fc=255;
        
if(bc>255) bc=255;
        
int r=fc+random.nextInt(bc-fc);
        
int g=fc+random.nextInt(bc-fc);
        
int b=fc+random.nextInt(bc-fc);
        
return new Color(r,g,b);
    }

%>
<%
  response
.setHeader("Pragma","No-cache");
  response
.setHeader("Cache-Control","no-che");
  response
.setDateHeader("Expires",0);
  
int width=60;
  
int height=20;
  BufferedImage image
=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
  Graphics g 
=image.getGraphics();
  Random  random
=new Random();
  g
.setColor(getRanColor(200,250));
  g
.fillRect(0,0,width,height);
  g
.setFont(new Font("Times New Roman",Font.PLAIN,18));
  g
.setColor(getRanColor(160,200));
 
      
for(int i=0;i<155;i++)
      {
          
int x=random.nextInt(width);
          
int y=random.nextInt(height);
          
int xl=random.nextInt(12);
          
int yl=random.nextInt(12);
          g
.drawLine(x,y,x+xl,y+yl);
      }
      String 
sRand="";
      
for(int i=0;i<4;i++)
      {
          String 
rand=String.valueOf(random.nextInt(10));
          
sRand+=rand;
          g
.setColor(new Color(20+random.nextInt(110),40+random.nextInt(110),60+random.nextInt(110)));
          g
.drawString(rand,13*i+6,16);
      }
   session
.setAttribute("rand",sRand);
   g
.dispose();
   ImageIO
.write(image,"JPEG",response.getOutputStream()); 
%>





Demo.jsp

<%@ page language="java" pageEncoding="gbk"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  
<head>
    
<html:base />
    
    
<title>Demo.jsp</title>

    
<meta http-equiv="pragma" content="no-cache">
    
<meta http-equiv="cache-control" content="no-cache">
    
<meta http-equiv="expires" content="0">    
    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    
<meta http-equiv="description" content="This is my page">
    
<!--
    
<link rel="stylesheet" type="text/css" href="styles.css">
    
-->

  
</head>
  
  
<body>&nbsp; 
  
<form action="Demo2.jsp">
   
<input type="text" name="asd" >     <img  border="0" src="Demo1.jsp" >
   
<br>
   
<input  type="submit" name="b"