2012年6月28日 星期四

[JAVA_程式分享]使用commons compress套件,使用壓縮檔zip、解壓縮unZip



package com.test;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.compress.utils.IOUtils;

/**
 * 
 * class name: ZipFileUtils
 * 
 * 使用Apache Commons Compress 套件
 * 
 * Apache Commons Compress software defines an API for working with compression and archive formats.
 * These include: bzip2, gzip, pack200, xz and ar, cpio, jar, tar, zip, dump.
 * 
 * 為何要使用此套件,因為使用java.util.zip套件作壓縮時,會中文檔名都會變亂碼。
 *  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4820807
 *  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4885817
 *  http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499
 * 
 * 使用說明:
 *  使用getInstance() 取得此 ZipFileUtils 物件。
 *  可使用二個public方法。
 *   1、unZip--解壓縮
 *   2、doZip--使用壓縮檔
 * 
* * @author Levin Li */ public class ZipFileUtils { /** * 設定編碼,BIG5 */ private final static String ENCODING_NAME = "BIG5"; /** * 存放解壓了那些文件明細 */ private final static List RETURN_FILE_LIST_DETAILS = new ArrayList(); /** * test * * @param args */ public static void main(String[] args) throws Exception { unZip(new File("d:/ZipTest.zip"), "d:/ZipTest"); doZip("d:/ZipTest1/ZipTest/"); } /** * 解壓指定zip文件 * ex:unZip(new File("d:/ZipTest.zip"),new File("d:/ZipTest")) * * @param pUnZipfile * 需要解壓的zip文件名 * @param pOutFileDir * 目的位置 * @return List 將解壓了那些文件明細 * @throws IOException * @author Levin Li */ public static List unZip(final File pUnZipFile, final String pOutFileDir) throws IOException { return unZip(pUnZipFile, new File(pOutFileDir)); } /** * 解壓指定zip文件 * ex:unZip(new File("d:/ZipTest.zip"), "d:/ZipTest") * * @param pUnZipFile * 需要解壓的zip文件名 * @param pOutFileDir * 目的位置 * @return List 將解壓了那些文件明細 * @throws IOException * @author Levin Li */ public static List unZip(final File pUnZipFile, final File pOutFileDir) throws IOException { ZipFile zipFile = null; try { /* * ZipFile API * :http://commons.apache.org/compress/apidocs/org/apache * /commons/compress/archivers/zip/ZipFile.html */ zipFile = new ZipFile(pUnZipFile, ENCODING_NAME); System.out.println("in pUnZipfile path:" + pUnZipFile.getPath()); for (Enumeration files = zipFile.getEntries(); files.hasMoreElements();) { ZipArchiveEntry zipArchiveEntry = files.nextElement(); /* * File.separator 用法。 該系統有關的默認名稱分隔符。 file.separator的值。 * 在UNIX系統上,此字段的值是'/',Microsoft Windows系統上,它是'\ \'。 */ File outFile = new File(pOutFileDir.getPath() + File.separator + zipArchiveEntry.getName()); // 如果指定文件的不存在,則創建. System.out.println("nuZip to file Name:" + outFile.getName()); // 這裡是指同層的檔案文件是不是目錄 if (!outFile.isDirectory()) { // 取得上一層目錄目錄創建。 if (!outFile.getParentFile().exists()) { outFile.getParentFile().mkdirs(); } /* * IOUtils API: * http://commons.apache.org/compress/apidocs/org * /apache/commons/compress/utils/IOUtils.html Copies the * content of a InputStream into an OutputStream. Uses a * default buffer size of 8024 bytes. */ copyFile(zipFile.getInputStream(zipArchiveEntry), outFile); // 加入已解壓完成的檔案資訊 RETURN_FILE_LIST_DETAILS.add(outFile); } else { System.out.println("isDirectory:" + outFile.getName()); outFile.mkdirs(); } } } catch (IOException ioe) { System.out.println("unZip Error Message:pUnZipfile path:" + pUnZipFile.getPath()); errorMessage(ioe); throw ioe; } finally { try { if (null != zipFile) { zipFile.close(); } } catch (IOException ioe) { errorMessage(ioe); throw ioe; } } return RETURN_FILE_LIST_DETAILS; } public static void doZip(final String pToZipFileSource) throws IOException { File toZipFile = new File(pToZipFileSource); // 壓縮後生成的zip文件名 String toZipFileName = toZipFile.getName() + ".zip"; String toZipDir = toZipFile.getParent() + toZipFileName; if (toZipFile.isDirectory()) { toZipDir = pToZipFileSource + toZipFileName; } doZip(toZipFile, new File(toZipDir)); } public static void doZip(final String pToZipFileSource, final String pToZipFileDir) throws IOException { doZip(new File(pToZipFileSource), new File(pToZipFileDir)); } /** *
  * doZip 此方法可以壓一個File,
  * 也可以壓一個目錄內的文件。
  * 
  * ex1:doZip("d:/ZipTest/ZipTest/test.txt", "d:/test/ZipTest.zip")
  * ex2:doZip("d:/ZipTest/ZipTest/", "d:/test/ZipTest.zip")
  * ex3:doZip("d:/ZipTest/ZipTest/")
  * 
  * 
* * @param pToZipFileSource * 目的文件夾 * @param pToZipFileDir * 要壓到那個目錄及檔名名字 * @throws IOException * @author Levin Li */ public static void doZip(final File pToZipFileSource, final File pToZipFileDir) throws IOException { ZipArchiveOutputStream zipFileOutput = null; File temp = null; try { System.out.println("檔案名稱zipDirectory:" + pToZipFileDir.getPath()); temp = File.createTempFile("temp", ".zip"); System.out.println(temp.getPath()); // 產出檔位置 zipFileOutput = new ZipArchiveOutputStream(new FileOutputStream(temp)); zipFileOutput.setEncoding(ENCODING_NAME); compress(pToZipFileSource, zipFileOutput, ""); zipFileOutput.close(); copyFile(temp, pToZipFileDir); } catch (SecurityException se) { errorMessage(se); } catch (IOException ioe) { errorMessage(ioe); } catch (Exception e) { errorMessage(e); } finally { try { if (null != zipFileOutput) { zipFileOutput.close(); } // if (null != temp) { // temp.deleteOnExit(); // } } catch (IOException ioe) { errorMessage(ioe); throw ioe; } } } /** * 判斷是目錄還是文件 * * @param pFile * 來源檔 * @param pZipArchiveOut * 輸出ZipArchiveOutputStream * @param baseDir * 在壓縮檔內的基本目錄 * @throws IOException * @author Levin Li */ private static void compress(final File pToZipFileSource, final ZipArchiveOutputStream pZipFileOutput, final String baseDir) throws IOException { /* 判斷是目錄還是文件 */ if (pToZipFileSource.isDirectory()) { compressDirectory(pToZipFileSource, pZipFileOutput, baseDir); } else { compressFile(pToZipFileSource, pZipFileOutput, baseDir); } } /** * 壓縮一個目錄,不壓縮上一層目錄名字的zip的檔 。 * * @param pToZipFileSource * 來源檔 * @param pZipArchiveOut * 輸出ZipArchiveOutputStream * @param baseDir * 在壓縮檔內的基本目錄 * @throws IOException * @author Levin Li */ private static void compressDirectory(final File pToZipFileSource, final ZipArchiveOutputStream pZipFileOutput, final String baseDir) throws IOException { File[] files = pToZipFileSource.listFiles(); for (int i = 0; i < files.length; i++) { System.out.println("files[i].getName():" + files[i].getName()); compress(files[i], pZipFileOutput, baseDir + pToZipFileSource.getName() + File.separator); } } /** * 壓縮一個文件 * * @param pFile * 來源檔 * @param pZipArchiveOut * 輸出ZipArchiveOutputStream * @param baseDir * 在壓縮檔內的基本目錄 * @throws IOException * @author Levin Li */ private static void compressFile(final File pToZipFileSource, final ZipArchiveOutputStream pZipFileOutput, final String baseDir) throws IOException { try { System.out.println("ready compression of file for:" + pToZipFileSource.getName()); pZipFileOutput.putArchiveEntry(new ZipArchiveEntry(baseDir + pToZipFileSource.getName())); copyFile(pToZipFileSource, pZipFileOutput); pZipFileOutput.closeArchiveEntry(); } catch (IOException ioe) { errorMessage(ioe); } } /** * 複製 * * @param inputFile * 來源檔File * @param outputFile * 輸出File * * @throws IOException * @author Levin Li */ private static void copyFile(File inputFile, File outputFile) throws IOException { BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); copyFile(inputFile, outputStream); } private static void copyFile(InputStream inputStream, File outputFile) throws IOException { BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); copyFile(inputStream, outputStream); } private static void copyFile(File inputFile, OutputStream outputStream) throws IOException { BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(inputFile)); copyFile(inputStream, outputStream); } /** * 複製 * * @param inputStream * 來源檔InputStream * @param outputStream * 輸出File * * @throws IOException * @author Levin Li */ private static void copyFile(InputStream inputStream, OutputStream outputStream) throws IOException { try { IOUtils.copy(inputStream, outputStream); } catch (IOException ioe) { errorMessage(ioe); } finally { try { if (null != outputStream) { outputStream.close(); } if (null != inputStream) { inputStream.close(); } } catch (IOException ioe) { errorMessage(ioe); } } } /** * 複製 * * @param inputFile * 來源檔InputStream * @param zipArchiveOutputStream * 輸出 * * @throws IOException * @author Levin Li */ private static void copyFile(File inputFile, ZipArchiveOutputStream zipArchiveOutputStream) throws IOException { BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(inputFile)); try { IOUtils.copy(inputStream, zipArchiveOutputStream); } catch (IOException ioe) { errorMessage(ioe); } finally { try { if (null != inputStream) { inputStream.close(); } } catch (IOException ioe) { errorMessage(ioe); } } } /** * 顯示錯誤訊息 * * @param ioe * IOException * @author Levin Li */ private static void errorMessage(Exception e) { StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); System.out.println("Error Message:" + stringWriter.toString()); } }

maven 設定

    <dependency>
<groupid>org.apache.commons</groupid>
<artifactid>commons-compress</artifactid>
<version>1.0</version>
</dependency>


download JAR

參考資料



















其它文章

[JAVA_Apache]使用commons compress套件,使用壓縮檔zip、解壓縮unZip

[JAVA_Apache]使用commons compress套件,使用壓縮檔zip、解壓縮unZip



java.util.zip無法處理與中國,日本,Unicode字符的文件名稱

使用commons compress套件
可以解決使用java.util.zip套件作壓縮時,為什麼中文檔名都會變亂碼的問題

是java 的bug
java bug_id 4820807
java bug_id 4885817
java bug_id 4244499



技術參考 api
Commons Compress 1.5-SNAPSHOT API

取得jar
apache compress 官網
maven


examples
apache examples


簡單的測試程式
package com.test;
import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;

public class ZipTest {

 public static void main(String[] args)  throws Exception{
  File zipFile = File.createTempFile("zipTest", ".zip");

     FileOutputStream fos = new FileOutputStream(zipFile);    
     ZipArchiveOutputStream aos = new ZipArchiveOutputStream(fos);
     aos.setEncoding("BIG5");
     try {
       ZipArchiveEntry entry = new ZipArchiveEntry("中文解壓測試.txt");
       aos.putArchiveEntry(entry);
       aos.write("中文解壓測試".getBytes());
       aos.closeArchiveEntry();      
     } finally {
       aos.close();
       fos.close();
     }
     //開啟檔案
     Desktop.getDesktop().open(zipFile);    
 }
}
參考

 [JAVA_程式分享]使用commons compress套件,使用壓縮檔zip、解壓縮unZip















其它文章

2012年6月25日 星期一

[JAVA_其它]利用itext來顯示pdf


最近作者比較有點空閒的時間,特別花了一點時間研究一下如何用java來寫入pdf,並用他來做一些基本的呈現,以及顯示中文

首先,先引入 itext-5.2.0.jar,如果你需要顯示中文化的話,需要引入itext-asian-5.2.0.jar

public class Emp {

 private String empNo;
 private String empName;
 private String birthday;
 private String year;
 private String tel;
 //以下為get,set
}
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import com.itextpdf.text.Anchor;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chapter;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Section;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;

public class ItxtSample {

 //產生中文字型
 private static Font fontRedCN, fontBlueCN, fontBlueSmallCN, fontBlackSmallCN;
 // 產生PDF路徑
 private static final String fileName = "C:/ItextSample.pdf";
 
 private static String empTitle[] = {"員工編號", "姓名", "生日", "電話", "年齡"};

 // 產生字型,字體大小
 private static final Font smallFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);

 private static Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);

 private static Font subFont = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD);

 public static void main(String[] args) throws DocumentException {
  //建立假資料
  java.util.List<Emp> list = FalseInformation();

  try {
   // 產生中文字型,字體大小
   BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
   fontRedCN = new Font(bfChinese, 18, Font.BOLD, new BaseColor(255, 0, 0));
   fontBlueCN = new Font(bfChinese, 18, Font.BOLD, new BaseColor(0, 0, 255));
   fontBlueSmallCN = new Font(bfChinese, 12, Font.BOLD, new BaseColor(0, 255, 0));
   fontBlackSmallCN = new Font(bfChinese, 12, Font.BOLD, new BaseColor(0, 0, 0));

   // 產生一個A4大小的PDF檔案
   Document document = new Document(PageSize.A4);

   PdfWriter.getInstance(document, new FileOutputStream(fileName));

   document.open();

   // PDF 文件內容部分
   addMetaDataTitle(document);
   // PDF 表頭部分
   addTitlePage(document);
   // PDF 內容部分
   addContent(document, list);

   document.close();

  } catch (DocumentException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

 /**
  * 假資料
  * @return
  */
 private static java.util.List<Emp> FalseInformation() {
  java.util.List<Emp> list = new ArrayList<Emp>();
  Emp emp = new Emp();
  emp.setEmpNo("000001");
  emp.setEmpName("王曉明");
  emp.setTel("031234567");
  emp.setYear("25");
  emp.setBirthday("1988/06/06");
  list.add(emp);
  Emp emp2 = new Emp();
  emp2.setEmpNo("000002");
  emp2.setEmpName("黃小強");
  emp2.setTel("037654321");
  emp2.setYear("52");
  emp2.setBirthday("1980/12/12");
  list.add(emp2);
  return list;
 }

 /**
  * PDF 內容部分
  * @param document
  * @param list
  * @throws DocumentException
  */
 private static void addContent(Document document, java.util.List<Emp> list) throws DocumentException {

  //建立標題一
  Anchor anchor = new Anchor("標題一", fontRedCN);
  anchor.setName("First Chapter");

  Chapter catPart = new Chapter(new Paragraph(anchor), 1);
  Paragraph subPara = new Paragraph("Subcategory 1", subFont);

  Section subCatPart = catPart.addSection(subPara);
  subCatPart.add(new Paragraph("Hello World"));

  Paragraph paragraph = new Paragraph();
  subCatPart.add(paragraph);

  addEmptyLine(paragraph, 10);

  subPara = new Paragraph("Subcategory 2", subFont);
  subCatPart = catPart.addSection(subPara);
  subCatPart.add(new Paragraph("Paragraph 1"));
  subCatPart.add(new Paragraph("Paragraph 2"));
  subCatPart.add(new Paragraph("Paragraph 3"));
  document.add(catPart);

  //建立標題二
  anchor = new Anchor("標題二", fontRedCN);
  anchor.setName("Second Chapter");

  catPart = new Chapter(new Paragraph(anchor), 2);
  subPara = new Paragraph("Subcategory 2", subFont);

  Section subCatPart2 = catPart.addSection(subPara);
  
  // Add a list
  createList(subCatPart2);
  // Add a table
  createTable(subCatPart2);
  // Add a table2
  createTable2(subCatPart2, list);

  document.add(catPart);

 }

 /**
  * 建立表格2
  * @param subCatPart2
  * @param list
  */
 private static void createTable2(Section subCatPart2, java.util.List<Emp> list) {
  
  PdfPTable table = new PdfPTable(5);
  PdfPCell cell = new PdfPCell(new Paragraph("員工基本資料", fontBlueCN));
  //字體內容至中
  cell.setHorizontalAlignment(Element.ALIGN_CENTER);
  // 背景顏色
  cell.setBackgroundColor(new BaseColor(0, 255, 0));
  // 外框顏色
  cell.setBorderColor(new BaseColor(255, 0, 0));
  //合併儲存格
  cell.setColspan(5);
  
  table.addCell(cell);
  
  for(String title : empTitle ){
   PdfPCell cell1 = new PdfPCell(new Paragraph( title, fontBlueSmallCN));
   cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
   table.addCell(cell1);
  }
  
  if( list != null && !list.isEmpty() ){
   for(Emp emp : list ){
    PdfPCell cell1 = new PdfPCell(new Paragraph( emp.getEmpNo(), catFont));
    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell1); 
    cell1 = new PdfPCell(new Paragraph( emp.getEmpName(), fontBlackSmallCN));
    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell1);
    cell1 = new PdfPCell(new Paragraph( emp.getBirthday(), catFont));
    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell1);
    cell1 = new PdfPCell(new Paragraph( emp.getTel(), catFont));
    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell1);
    cell1 = new PdfPCell(new Paragraph( emp.getYear(), catFont));
    cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(cell1);
   }
  }
  subCatPart2.add(table);
 }

 /**
  * 建立表格
  * @param subCatPart
  */
 private static void createTable(Section subCatPart2) {
  PdfPTable table = new PdfPTable(3);
  //表格與上排字體間隙
  table.setSpacingBefore(5);
  //表格與下排字體間隙
  table.setSpacingAfter(5);
       
  PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
  //字體至中
  c1.setHorizontalAlignment(Element.ALIGN_CENTER);
  table.addCell(c1);

  c1 = new PdfPCell(new Phrase("Table Header 2"));
  c1.setHorizontalAlignment(Element.ALIGN_LEFT);
  table.addCell(c1);

  c1 = new PdfPCell(new Phrase("Table Header 3"));
  c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
  table.addCell(c1);
  table.setHeaderRows(1);

  table.addCell("1.0");
  table.addCell("1.1");
  table.addCell("1.2");
  table.addCell("2.1");
  table.addCell("2.2");
  table.addCell("2.3");

  subCatPart2.add(table);
  
 }

 /**
  * 增加list
  * @param subCatPart
  */
 private static void createList(Section subCatPart) {
  List list = new List(true, false, 10);
  //list.add(new ListItem("標題二", fontRedCN));
  list.add(new ListItem("First point"));
  list.add(new ListItem("Second point"));
  list.add(new ListItem("Third point"));
  subCatPart.add(list);
 }

 /**
  * 表頭部分
  * @param document
  * @throws DocumentException
  */
 private static void addTitlePage(Document document)throws DocumentException {

  Paragraph preface = new Paragraph("This is a paragraph", 
                  FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC,new BaseColor(0, 0, 255)));

  //換行
  addEmptyLine(preface, 2);

  preface.add(new Paragraph("顯示中文", fontRedCN));

  addEmptyLine(preface, 2);

  preface.add(new Paragraph(addBlank(3) + "顯示中文", fontRedCN));

  addEmptyLine(preface, 8);

  preface.add(new Paragraph("This document is a preliminary version and not subject to your li cense agreement or any other agreement with vogella.com ;-).", smallFont));

  addEmptyLine(preface, 4);
  
  document.add(preface);
  
  Phrase phrase0 = new Phrase("PDF");
  Phrase phrase1 = new Phrase(new Chunk("字體顏色", fontRedCN));
  Phrase phrase2 = new Phrase(new Chunk("測試", fontBlueCN));
  document.add(phrase0);
  document.add(phrase1);
  document.add(phrase2);
  // 產生新的一頁
  document.newPage();
 }

 /**
  * 文件內容部分
  * @param document
  */
 private static void addMetaDataTitle(Document document) {

  // 增加標題
  document.addTitle("PDF表頭");
  // 增加作者
  document.addAuthor("Puma製作");
  // 增加建立PDF時間以及修改PDF日期
  document.addCreationDate();
  // 增加PDF中的關鍵字
  document.addKeywords("關鍵字");
  // 增加PDF的主題
  document.addSubject("PDF TEST");
  // 增加自訂內容
  document.addHeader("PDF1", "測試1");
  document.addHeader("PDF2", "測試2");

 }

 /**
  * 換行
  * @param paragraph
  * @param number
  */
 private static void addEmptyLine(Paragraph paragraph, int number) {
  if (number != 0) {
   for (int i = 0; i < number; i++) {
    paragraph.add(new Paragraph(" "));
   }
  }
 }

 /**
  * 增加空白
  * @param blank
  * @return
  */
 private static String addBlank(int blank) {
  StringBuilder bu = new StringBuilder();
  if( blank > 0 ){
   for (int i = 0; i <= blank; i++) {
    bu.append(" ");
   }
  }
  return bu.toString();
 }
}
結果






















其它文章

2012年6月19日 星期二

[Linux]LAMP 安裝(Linux Apache Mysql Php四種軟體的縮寫)

[Linux]LAMP 安裝
安裝 LAMP
不是在 本機上安裝
而是透過 ssh 遠端連線  軟體: pietty0327
把檔案傳到 linux上  軟體 WinSCP


LAMP 就是 Linux Apache Mysql Php四種軟體的縮寫....

系統環境
Linux OS 版本:CentOS 5.3

安裝方式 yum
由於yum非常強大便利 所以現在都用yum方式安裝

ps.用yum安裝 會依據目前Linux核心版本 決定安裝的程式版本新舊
   由於目前的版本不適合 所以得更新yum的核心(yum核心的功能 有點類似於 軟體伺服器)

使用YUM安裝(安裝指令)
# yum install 安裝的軟體名稱
#yum remove 移除的軟體名稱

#軟體名稱 -v  (查詢軟體版本)
ex.
#mysql -v

LAMP 安裝順序
1.Apache
2.MySql
3.PHP



1.安裝 Apache
安裝版本:2.2.3
#yum install httpd

啟動 Apache
#service httpd start
停止 Apache
#service httpd stop

1-2.Apache  設定 更改./etc/httpd/conf/httd.conf 檔案
ServerName IP位置:80



2.安裝MySql
要安裝 mysql client版本 & server版本
安裝版本:5.0.77
#yum install mysql
#yum install mysql-server

啟動Mysql
#service mysqld start
停止Mysql
#service mysqld stop

可用2-1設定密碼或用2-2變更密碼
2-1.啟動 MySQL 以後,必須設定 root 的密碼
# mysqladmin -u root password ' 密碼 '
2-2.安裝完成後 登入mysql 修改root密碼(一般安裝完沒有密碼)
#mysql -u root -pd密碼

2-A.卻發生了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 導致無法登入
解決方法:
停止Mysql服務
#service mysqld stop
進入安全模式
# mysqld_safe --skip-grant-table
已root進入mysql DB
# mysql -u root mysql

update root 密碼
mysql> UPDATE user SET Password=PASSWORD('要更換的密碼') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

接者重新啟動mysql 即可......



安裝PHP
安裝版本 5.2.0
因為需要安裝phpMyAdmin但是CentOS 5.3 yum的核心太舊 只能安裝php5.1.16
所以只好 升級yum的核心 另一起更新的Server
#rpm -ivh http://repo.webtatic.com/yum/centos/5/`uname  -i`/webtatic-release-5-0.noarch.rpm


因為5.3.X板的php 有問題 所有不安裝5.3.X板 安裝指令為下
#yum --disablerepo=* --enablerepo=webtatic --exclude=php*5.3* install php exclude=php*5.3*   <=== 不安裝 PHP 5.3以後的版本(包含5.3)
因為 如果之前安裝的是5.1.16版本
安裝完 要先確認 httpd/modules裡 會多一個libphp5.so     ps.如果安裝5.2.0之後會自動安裝libphp5.so
這個檔案要確定有裝起來 再去升級.....



安裝phpMyAdmin
版本:3.4.8

到網址:http://www.phpmyadmin.net/home_page/downloads.php

下載 解壓縮後 將檔案
設定libraries底下的config.default檔案

設定
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['user'] = 'mysql帳號';
$cfg['Servers'][$i]['password'] = 'mysql密碼';
$cfg['PmaAbsoluteUri'] = 'http://IP位置/phpMyAdmin/';

設定完後 將整個資料夾移到./var/www/html/
重啟Apache即可


安裝TOMCAT
到  http://tomcat.apache.org/download-60.cgi  下載tomcat 6系列的
下完解壓縮
將 TOMCAT 整個資料夾複製 進 linux
執行 ./startup
關閉 killall -9 java



phpmyadmin設定時 發生 需要使用 mcrypt 函式
版本
rpm -qa |grep php

解決方法 要安裝下列幾個套件
php-mysql
php-mbstring
php-mhash
php-mcrypt


yum --disablerepo=* --enablerepo=webtatic --exclude=php-mcrypt*5.3* install php-mcrypt exclude=php-mcrypt*5.3*

最後重新啟動httpd服務就可以囉!
# service httpd restart

安裝完無法啟動 碰到兩個問題

一個是Mysql 無法連線.....
原因
$cfg['Servers'][$i]['host'] = '設成IP';
Mysql root 沒有該IP 權限
解決方法
1.改成$cfg['Servers'][$i]['host'] = 'localhost';
2.修改root權限

二 啟動後 連線看到整個目錄 無法進入index.php
解決方法 php 缺libphp5.so檔
重新安裝 php
yum --disablerepo=\* --enablerepo=c5-testing install php
核心 >> c5-testing
linux核心類似 軟體伺服器提供軟體清單下載安裝 

如果嫌 tomcat log 太大 可以在 安裝 Cronolog 套件 可以將log 做切割

















其它文章

2012年6月17日 星期日

[JAVA_Apache]有幫程式設計師設計BeanUtils工具套件

BeanUtils是一種非常實用的JavaBean,在apache底下的一個組件,我稍微介紹一下它的實用性,等等用程式碼來代表就清楚了,首先需要先把 commons-beanutils-1.8.3.jar 和 commons-logging-1.1.1.jar 導入,再將bean屬性建置好

public class User {

 private String username;

 private String password;

 private String attribute;

 private Long userId;

 private Profile profile;

 //以下get,set
}
public class Profile {

 private String email;

 private Date birthDate;

 private Address[] address;

 private Map phone;
 
 private HashMap telephone;

 //以下get,set
}
public class Address {

 private String country;

 private String city;

 private String addr;

 private String postcode;

 public Address(String country, String city, String addr, String postcode) {
  this.country = country;
  this.city = city;
  this.addr = addr;
  this.postcode = postcode;
 }

//以下get,set
}

import java.lang.reflect.InvocationTargetException;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;

import BeanUtils.Address;
import BeanUtils.Profile;
import BeanUtils.User;

public class BeanUtilExample {

 //建立假資料
 public User prepareDate() throws IllegalAccessException, InvocationTargetException {
  Profile profile = new Profile();

  profile.setEmail("pp@gmail.com");
  profile.setBirthDate(new GregorianCalendar(2012, 06, 16).getTime());

  Map phone = new HashMap();
  phone.put("home", "(03)XXXXXXX");
  phone.put("office", "(02)1234-5678");
  phone.put("mobile", "09XX-XXX-XXX");
  profile.setPhone(phone);
  
  Address addr1 = new Address("台灣省", "桃園縣中壢市", "XX路", "100001");
  Address addr2 = new Address("台灣省", "台北市中山區", "XXX路", "100002");
  Address[] address = { addr1, addr2 };
  profile.setAddress(address);

  User user = new User();
  user.setUserId(new Long(123456789));
  user.setUsername("puma");
  user.setPassword("987654321");
  user.setAttribute("男");
  user.setProfile(profile);
  
  return user;
 }

 public static void main(String[] args) {

  BeanUtilExample example = new BeanUtilExample();
  
  try {
   User user = example.prepareDate();
   //取值方式
   System.out.println(BeanUtils.getProperty(user, "userId"));
   System.out.println(PropertyUtils.getProperty(user, "userId"));
   System.out.println(BeanUtils.getProperty(user, "username"));
   System.out.println(BeanUtils.getProperty(user, "password"));
   System.out.println(BeanUtils.getProperty(user, "attribute"));
   System.out.println(BeanUtils.getProperty(user, "profile"));
   System.out.println(BeanUtils.getProperty(user, "profile.email"));
   System.out.println(BeanUtils.getProperty(user, "profile.birthDate"));
   System.out.println(BeanUtils.getProperty(user,  "profile.phone" ));
   System.out.println(BeanUtils.getProperty(user,  "profile.phone(mobile)" ));
   System.out.println(BeanUtils.getProperty(user,  "profile.phone(office)" ));
   System.out.println(BeanUtils.getProperty(user,  "profile.phone(home)" ));
   System.out.println(BeanUtils.getProperty(user,  "profile.address[0].country" ));
   System.out.println(BeanUtils.getProperty(user,  "profile.address[0].city" ));
   System.out.println(BeanUtils.getProperty(user,  "profile.address[0].postcode" ));
         
   System.out.println("--------------------------------------------------------------------");
       
   User user2 =  new  User();
   BeanUtils.copyProperties(user2, user);  //將user這物件轉至user2
   System.out.println(BeanUtils.getProperty(user2,  "userId" ));  //輸出user類的userId的值
   System.out.println(PropertyUtils.getProperty(user2,  "userId" ));
   System.out.println(BeanUtils.getProperty(user2,  "username" ));
   System.out.println(BeanUtils.getProperty(user2,  "password" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.email" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.birthDate" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.phone" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.phone(mobile)" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.phone(office)" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.phone(home)" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.address[0].country" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.address[0].city" ));
   System.out.println(BeanUtils.getProperty(user2,  "profile.address[0].postcode" ));
         
   System.out.println("--------------------------------------------------------------------");
         
   Profile profile = new Profile();
   HashMap map = new HashMap();

   map.put( "1", "13880808080" );
   map.put( "2", "13550505050" );
   BeanUtils.setProperty( profile, "telephone", map );
   System.out.println(BeanUtils.getProperty( profile, "telephone(1)" ));
         
  } catch (IllegalAccessException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (InvocationTargetException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (NoSuchMethodException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}




結果

123456789
123456789
puma
987654321
BeanUtils.Profile@66388993
pp@gmail.com
Mon Jul 16 00:00:00 CST 2012
{office=(02)1234-5678, home=(03)XXXXXXX, mobile=09XX-XXX-XXX}
09XX-XXX-XXX
(02)1234-5678
(03)XXXXXXX
台灣省
桃園縣中壢市
100001
--------------------------------------------------------------------
123456789
123456789
puma
987654321
BeanUtils.Profile@66388993
pp@gmail.com
Mon Jul 16 00:00:00 CST 2012
{office=(02)1234-5678, home=(03)XXXXXXX, mobile=09XX-XXX-XXX}
09XX-XXX-XXX
(02)1234-5678
(03)XXXXXXX
台灣省
桃園縣中壢市
100001
--------------------------------------------------------------------
15136125313
















其它文章

2012年6月14日 星期四

[jQuery] 月曆套件 (二)

[jQuery] 月曆套件 (二)
其實上一版月曆有支援國際化的功能,我就中文月曆好了,要放入jquery-ui-i18n.js即可完成


<script type="text/javascript">

$().ready(function(){

$( "#date" ).datepicker({
dateFormat: 'yy/mm/dd',
showOn: "button",
buttonImage: "./jquery-ui-1.8.21.custom/css/smoothness/images/calendar.gif",
buttonImageOnly: true
});
});
</script>


</head>
<body>
<input size="10" type="text" id="date" readonly="readonly" />
</body>
</html>



[JAVA_WEB]JAVA 驗證碼

[JAVA_WEB]JAVA 驗證碼

我相信驗證碼很多網頁都見的到,所以我找了一個比較簡單的版本分享給大家,
相信大家很容易就上手
首先,要先將 kaptcha 這jar包放入lib裡 ,接下來你只要編輯一隻jsp和設定web.xml即可

jsp部分


<body>
<table>
<tr>
<td><img src="Kaptcha.jpg"></td>
<td valign="top">
<form method="POST">
<br>請輸入驗證碼:<input type="text" name="kaptchafield"><br />
<input type="submit" name="submit">
</form>
</td>
</tr>
</table>


<%
String c = (String)session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
String parm = (String) request.getParameter("kaptchafield");

out.println("Parameter: " + parm + " ? Session Key: " + c + " : ");

if (c != null && parm != null) {
if (c.equals(parm)) {
out.println("<b>true</b>");
} else {
out.println("<b>false</b>");
}
}
%>

</body>

web.xml 部分


<servlet>
<servlet-name>Kaptcha</servlet-name>
<servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
<!-- 是否要有邊框 -->
<init-param>
<param-name>kaptcha.border</param-name>
<param-value>yes</param-value>
</init-param>

        <!-- 字體顏色 -->
<init-param>
<param-name>kaptcha.textproducer.font.color</param-name>
<param-value>black</param-value>
</init-param>
        <!-- 驗證碼與驗證碼的間隙 -->
<init-param>
<param-name>kaptcha.textproducer.char.space</param-name>
<param-value>5</param-value>
</init-param>

<!-- 背景顏色開始點 -->
<init-param>
<param-name>kaptcha.background.clear.from</param-name>
<param-value>100,150,250</param-value>
</init-param>

<!-- 背景顏色結束點 -->
<init-param>
<param-name>kaptcha.background.clear.to</param-name>
<param-value>250,150,100</param-value>
</init-param>

</servlet>

<servlet-mapping>
<servlet-name>Kaptcha</servlet-name>
<url-pattern>/Kaptcha.jpg</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>KaptchaExample.jsp</welcome-file>
</welcome-file-list>

他有一些參數可以調整,可到 Wiki 看參數設定

結果畫面


輸入錯誤的驗證碼

結果

輸入正確的驗證碼

結果







2012年6月12日 星期二

[JAVA_Apache]POI套件的使用_產出EXCEL文件_儲存格的樣式使用方法(CellStyle)

POI的使用
[JAVA_Apache]POI套件的使用_產出EXCEL文件_儲存格的樣式使用方法(CellStyle)


使用儲存格 設定為日期格式
 
public static void training5() throws IOException {
  Workbook wb = new HSSFWorkbook();
     //or Workbook wb = new XSSFWorkbook();
     CreationHelper createHelper = wb.getCreationHelper();
     Sheet sheet = wb.createSheet("new sheet");

     // Create a row
     Row row = sheet.createRow(0);
     // as a date.
     Cell cell = row.createCell(0);
     cell.setCellValue(new Date());

     CellStyle cellStyle = wb.createCellStyle();
     cellStyle.setDataFormat(
         createHelper.createDataFormat().getFormat("m/d/yy h:mm"));
    
     cell = row.createCell(1);
     cell.setCellValue(new Date());
     cell.setCellStyle(cellStyle);

     //you can also set date as java.util.Calendar
     cell = row.createCell(2);
     cell.setCellValue(Calendar.getInstance());
     cell.setCellStyle(cellStyle);

     // Write the output to a file
     FileOutputStream fileOut = new FileOutputStream("workbook.xls");
     wb.write(fileOut);
     fileOut.close();
 }


 
public static void training6() throws IOException {
  Workbook wb = new HSSFWorkbook();
  // or Workbook wb = new XSSFWorkbook();
  CreationHelper createHelper = wb.getCreationHelper();
  Sheet sheet = wb.createSheet("new sheet");
  // Create a row
  Row row = sheet.createRow(0);
  Cell cell = row.createCell(0);
  // 第一種:日期格式
  
  cell.setCellValue(new Date());
  CellStyle cellStyle = wb.createCellStyle();
  DataFormat format = wb.createDataFormat();//
  cellStyle.setDataFormat(format.getFormat("yyyy年m月d日"));
  cell.setCellStyle(cellStyle);
  
  // 第二種:保留兩位小數格式
  cell = row.createCell(1);
  cell.setCellValue(1.2);
  CellStyle cellStyle2 = wb.createCellStyle();
  cellStyle2.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
  cell.setCellStyle(cellStyle2);
  // 第三種:貨幣格式
  cell = row.createCell(2);
  cell.setCellValue(20000);
  CellStyle cellStyle3 = wb.createCellStyle();
  DataFormat format3 = wb.createDataFormat();
  cellStyle3.setDataFormat(format3.getFormat("$#,##0"));
  cell.setCellStyle(cellStyle3);
  // 第四種:百分比格式
  cell = row.createCell(3);
  cell.setCellValue(20);
  CellStyle cellStyle4 = wb.createCellStyle();
  cellStyle4.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));
  cell.setCellStyle(cellStyle4);
  // 第五种:中文大寫格式
  cell = row.createCell(4);
  cell.setCellValue(20000);
  CellStyle cellStyle5 = wb.createCellStyle();
  DataFormat format5 = wb.createDataFormat();
  cellStyle5.setDataFormat(format5.getFormat("[DbNum2][$-804]0"));
  cell.setCellStyle(cellStyle5);
  // 第六種:科學格式
  cell = row.createCell(5);
  cell.setCellValue(20000);
  CellStyle cellStyle6 = wb.createCellStyle();
  cellStyle6.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00E+00"));
  cell.setCellStyle(cellStyle6);
  // 第七種:自訂格式
  cell = row.createCell(6);
  cell.setCellValue(-20000);
  CellStyle cellStyle7 = wb.createCellStyle();
  DataFormat format7 = wb.createDataFormat();
  cellStyle7.setDataFormat(format7.getFormat("$#,##0.00_ ;[red](-$#,##0.00)"));
  cell.setCellStyle(cellStyle7);
  // Write the output to a file
  FileOutputStream fileOut = new FileOutputStream("workbook.xls");
  wb.write(fileOut);
  fileOut.close();
 }
格式可找在excel裡的儲存格樣式->自訂
如圖










其它文章

[JAVA_Apache]POI套件的使用_產出EXCEL文件_儲存格的使用方法(Cell、row、column)

POI的使用
[JAVA_Apache]POI套件的使用_產出EXCEL文件_儲存格的使用方法(Cell、row、column)



 
public static void training4() throws IOException {
  Workbook wb = new HSSFWorkbook();
  //or Workbook wb = new XSSFWorkbook();
  Sheet sheet = wb.createSheet("new sheet");
  //一列(1、2、3…)  row ,從0開始
  //使用第一列
  Row row = sheet.createRow((short) 0);
  //創建一個儲存格
  //位置(row:column)
  //    A    B     C    D
  //1  0:0  0:1   0:2  0:3
  //2  1:0  1:1   1:2  1:3
  //3  2:0  2:1   2:2  2:3
  //使用第一列的第一個儲存格
  //方法一
  Cell cell = row.createCell(0);
  cell.setCellValue(1);
  //方法二
  row.createCell(1).setCellValue(1.5);
  //方法三
  CreationHelper createHelper = wb.getCreationHelper();
  row.createCell(2).setCellValue(createHelper.createRichTextString("test"));
  //方法四
  row.createCell(3).setCellValue(true);
  //方法五
  row.createCell(4).setCellValue("cell");
  //產出內容位置 
  //   A    B        C    D      E
  //1  1  1.5     test   TRUE   cell
  FileOutputStream fileOut = new FileOutputStream("workbook.xls");
  wb.write(fileOut);
  fileOut.close();
 }











其它文章

[JAVA_Apache]POI套件的使用_產出EXCEL文件_創建EXCEL裡工作表的方法(Sheet)

POI的使用
[JAVA_Apache]POI套件的使用_產出EXCEL文件_創建EXCEL裡工作表的方法(Sheet)

產生新的工作表

 
public static void training3() throws IOException {
  FileOutputStream fileOut = null;
  try {
   // 這裡只純產生新的工作表
   // 產出Excel 97(XLS)文件格式
   Workbook wb = new HSSFWorkbook(); // or new XSSFWorkbook();
   Sheet sheet1 = wb.createSheet("new sheet");
   Sheet sheet2 = wb.createSheet("second sheet");
   //另外如果是取得原來就有的excel裡的工作表
   //方法一 :取得工作表名稱為:工作表1
   //wb.getSheet("工作表1");
   //方法二 :
   //此方法 是要看在excel中的工作表順序
   //hssfWorkbook.getSheetAt(0);
   fileOut = new FileOutputStream("workbook.xls");
   wb.write(fileOut);
   fileOut.close();
  }
  catch (IOException ioe) {
   ioe.printStackTrace();
  }
  finally {
   if (null != fileOut) {
    fileOut.close();
   }
  }
 }












其它文章

[JAVA_Apache]POI套件的使用_產出EXCEL文件_產出EXCEL方法(Workbook)

POI的使用
[JAVA_Apache]POI套件的使用_產出EXCEL文件_產出EXCEL方法(Workbook)

           
public static void training1() throws IOException {
 FileOutputStream fileOut = null ;
  try {
   //這裡只是純產出excel檔案而以
   //產出Excel 97(XLS)文件格式
   Workbook hssfwb = new HSSFWorkbook();
   fileOut = new FileOutputStream("workbook.xls");
   hssfwb.write(fileOut);
   fileOut.close();
   //Excel 2007的(XLSX)文件格式
   Workbook xssfwb = new XSSFWorkbook();
   fileOut = new FileOutputStream("workbook.xlsx");
   xssfwb.write(fileOut);
   fileOut.close();
  }
  catch (IOException ioe) {
   ioe.printStackTrace();
  }
  finally {
   if (null != fileOut) {
    fileOut.close();
   }
  }
 }


 
public static void training2() throws IOException {
  // 讀取一個原有的excel檔案
  FileInputStream fileInputStream = null;
  Workbook hssfWorkbook = null;
  try {
   fileInputStream = new FileInputStream(new File("D:/training1.xls"));
   if (null != fileInputStream) {
    try {
     hssfWorkbook = new HSSFWorkbook(fileInputStream);
    }
    catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
  catch (IOException ioe) {
   ioe.printStackTrace();
   throw ioe;
  }
  finally {
   if (null != fileInputStream) {
    fileInputStream.close();
   }
  }
  //將剛讀取的excel檔案,產出為另一個excel檔案。
  FileOutputStream fileOutputStream = null;
  try {
   fileOutputStream = new FileOutputStream(new File("D:/trainingto.xls"));
   hssfWorkbook.write(fileOutputStream);
   fileOutputStream.flush();
  }
  catch (IOException ioe) {
   ioe.printStackTrace();
   throw ioe;
  }
  finally {
   if (null != fileOutputStream) {
    fileOutputStream.close();
   }
  }
 }











其它文章

2012年6月11日 星期一

[JAVA_Apache]POI套件的使用_產出EXCEL文件基本認識及JAR檔的取得

POI的使用
[JAVA_Apache]POI套件的使用_產出EXCEL文件基本認識及JAR檔的取得

一、取得JAR檔
        官網download
         Maven 參數

二、基本認識
       1、Microsoft Excel格式文件
             POI 不支援Excel 5.0/7.0 (BIFF5)

             目前POI有只支援BIFF8格式,POI分別名為HSSF(.xls)及XSSF(.xlsx).
              POI HSSF:Excel 97(XLS)文件格式
              POI XSSF:Excel 2007的(XLSX)文件格式。
              這裡只說明HSSF及XSSF,其它詳官網
        2、POI與EXCEL對應名稱
           
EXCEL
POI
一個EXCEL
Workbook
一個工作表1
Sheet
一列(123)
row
一欄(ABC)
column
儲存格格式
CellStyle



          3、POI官網開發指南












其它文章

2012年6月9日 星期六

[jQuery] 月曆套件(一)

[jQuery] 月曆套件
我相信很多人在編輯前端頁面的時候,一定會需要用到月曆的套件,今天我來介紹一下juery的月曆套件,過程還蠻簡單的

當然要先抓取jquery的js檔案嚕,作者適用jquery164的,另外還要抓另外抓取jQuery的元件

我是用  jquery-ui-1.8.18.custom.js 以及 jquery-ui-1.8.18.custom.css ,另外再抓取想用來顯示月曆的圖片或者其他就可

以了,以下是程式碼

 <script type="text/javascript">

$().ready(function(){

$( "#date" ).datepicker({
changeMonth: true,     //可以限定是否需要月份的下拉是選單,預設是沒有
changeYear: true,   //可以限定是否需要年份的下拉是選單,預設是沒有
dateFormat: 'yy/mm/dd',  //所顯示的default
showOn: "button",            
buttonImage: "./resources/images/icon/calendar.gif",
buttonImageOnly: true
});
});
 </script>

</head>
<body>
<input size="10"  type="text" id="date" readonly="readonly" />
</body>
</html>

以下是顯示畫面唷


按下去後






這就是月曆,還不錯用唷
參考網站 jquery官網  http://jqueryui.com/





標籤

Oracle (150) Oracle DB (144) Oracle_DB (143) Oracle SQL (135) JAVA (84) css-基本類 (65) MySQL (59) CSS Selector (58) jQuery (49) JavaScript-基本類 (39) Spring Boot (38) JavaScript (37) JavaScript HTML DOM (37) JavaScript-HTML_DOM (36) CSS3 (30) JAVA-基本類 (28) jQuery UI (27) Apache (23) Oracle GROUP BY (20) datepicker (20) Android (18) Oracle Date (17) c (17) JAVA-lang套件 (16) Linux (16) Oracle Sub Query (16) Spring-基本類 (16) jQuery-基本類 (16) MySQL-進階系列教學 (15) Android基本類 (14) Grails (14) Oracle join (14) SQLite (13) Spring (13) WIN7-基本類 (13) grails-基本類 (13) linux cent os (13) CKEditor (12) JAVA-流程控制類 (12) JAVA_Spring (12) PHP (11) Spring MVC (11) MySQL-基本系列教學 (10) Notepad (10) Notepad++ (10) SQLite for java (10) Windows (10) c/c++ (10) eclipse (9) jQuery-Selector (9) sqldeveloper (9) DB_Toad (8) JAVA_IDE_Eclipse (8) JavaScript-String類 (8) MySQL DB Toad (8) MySQL-DATE相關 (8) MySQL-函式相關 (8) Spring Bean (8) Android Studio (7) HTML5 (7) Hibernate (7) JAVA-OCWCD (7) JavaScript-陣列類 (7) Docker (6) JAVA-程式分享 (6) JAVA.util套件 (6) JavaScript-數學類 (6) MinGw (6) MySQL-其它類 (6) Servlet (6) centos (6) Apache_Tomcat (5) Apache套件_POI (5) CSS (5) JavaScript-Date物件 (5) JavaScript-其它類 (5) PostgreSQL (5) httpd (5) log4j (5) 基本資訊 (5) 開發工具 (5) CSS Properties (4) Dev-C++ (4) IntelliJ IDEA (4) Oracle DDL (4) Sublime (4) TortoiseSVN (4) apache_Maven (4) Android NDK (3) Eclipse IDE for C/C++ (3) Hibernate-基本類 (3) JAVA-問題 (3) JAVA-綀習分享 (3) JVM (3) Linux 指令 (3) Proxy Server (3) Spring Mobile (3) Spring web (3) Squid (3) VirtualBox (3) maven (3) zk (3) 生活其它 (3) Bootstrap (2) Filter (2) JAVA_IO (2) JAVA_其它_itext套件 (2) JBoss-問題 (2) JSP (2) Jboss (2) Listener (2) MySQL-語法快速查詢 (2) Spring AOP (2) Spring Batch (2) Spring Boot Actuator (2) Spring i18n (2) Subversive (2) Tomcat 8 (2) UML (2) WebJars (2) WinMerge (2) c++ (2) c語言綀習題 (2) jQuery Mobile (2) jQuery-事件處理 (2) jQuery-套件類 (2) putty (2) svn (2) weblogic (2) Apache_JMeter (1) Apache套件_BeanUtils (1) Apache套件_StringUtils (1) Base64 (1) Google API (1) HTML5-基本類 (1) Heap (1) JAVA 7 (1) JAVA SE 、JAVA EE、JAVA ME (1) JAVA 日期 (1) JAVA-OCJP (1) JAVA-WEB (1) JAVA_IDE (1) JAVA其它 (1) JBoss Server (1) JDK (1) JMX (1) JRE (1) Java RMI (1) Java String (1) Joda Time (1) Linux_其它 (1) MySQL教學 (1) Oracle_VirtualBox (1) SQL Server (1) SWT (1) Session (1) Stack (1) Struts 2 (1) Tool (1) ZK Studio (1) csv (1) grails-其它類 (1) jQuery-進階 (1) java mail (1) java web (1) java8 (1) jsoup (1) mockmvc (1) modules (1) tomcat (1) win10 (1) 其它類 (1) 圖片工具 (1) 模擬器 (1) 讀書分享 (1) 開發資訊 (1)

精選文章

初學 Java 的 HelloWorld 程式

撰寫一個JAVA程式 public class HelloWorld{ public static void main(String[ ] args){ System.out.println("我第一支Java程式!!"); } } ...