久久无码av亚洲精品色午夜,亚洲国产成人精品无码区花野真一,亚洲国产美女精品久久久久∴http://www.tkk7.com/xlth2006/category/41750.html學習才是唯一的出路zh-cnThu, 09 Jun 2011 06:22:30 GMTThu, 09 Jun 2011 06:22:30 GMT60我的獨立博客已經開通,歡迎大家訪問http://www.tkk7.com/xlth2006/archive/2011/06/09/351974.html鐵猴鐵猴Thu, 09 Jun 2011 05:30:00 GMThttp://www.tkk7.com/xlth2006/archive/2011/06/09/351974.htmlhttp://www.tkk7.com/xlth2006/comments/351974.htmlhttp://www.tkk7.com/xlth2006/archive/2011/06/09/351974.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/351974.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/351974.html我的獨立博客已經開通,歡迎大家訪問,


編程學習網



J-CN工作室論壇

鐵猴 2011-06-09 13:30 發表評論
]]>
Struts實現多國語言切換http://www.tkk7.com/xlth2006/archive/2009/11/01/300558.html鐵猴鐵猴Sun, 01 Nov 2009 04:37:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/11/01/300558.htmlhttp://www.tkk7.com/xlth2006/comments/300558.htmlhttp://www.tkk7.com/xlth2006/archive/2009/11/01/300558.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/300558.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/300558.html摘要:
通過下拉框里各個語言(中文,日本語,English)的選擇,切換jsp頁面文字。
tyrone1979 發表于 2005-08-26 13:27:19
作者:tyrone1979     來源:blog.csdn.net/tyrone1979
1 準備資源文件。

資源文件命名格式:filename_language_country.properties.
中文文件名為index_zh_CN.properties。
日文文件名為 index_ja_JP.properties。
英文文件名為 index_en.properties。

英文文件內容:

index.jsp.welcome=Colimas Library Management System
index.jsp.name=Name
index.jsp.userid=User ID
index.jsp.pass=Password


中文文件內容:

index.jsp.welcome=\u4f60\u597d
index.jsp.name=\u59d3\u540d
index.jsp.userid=\u7528\u6237\u540d
index.jsp.pass=\u5bc6\u7801


日文文件內容:

index.jsp.welcome=\u3044\u3089\u3063\u3057\u3083\u3044\u307e\u305b
index.jsp.name=\u59d3\u540d
index.jsp.userid=\u30e6\u30fc\u30b6\u30fcID
index.jsp.pass=\u30d1\u30b9\u30ef\u30fc\u30c9

\uxxxx是中文被轉換后的ASCII碼。可以使用native2ascii.exe工具轉換。

2 struts-config.xml里配置資源文件
   
<message-resources parameter="resources.config.index" />

resources.config.index是classes目錄下的resources/config子目錄的index__xx_xx.properties文件.
struts根據你的瀏覽器的語言設置調用不同語言的資源文件。
例如:如果你的IE默認語言為中文則。Struts將使用index_zh_CN.properties。而在struts-config.xml里只需寫出“index”即可

ActionMapping
 
<form-beans>
                <!--1 Multi-Lanuage support formbean-->
        <form-bean
            name="SelectLanguageForm"
            type="com.nova.colimas.web.form.SelectLanguageForm"/>
   </form-beans>
<!-- =========================================== Global Forward Definitions -->

    <global-forwards>
        <!-- Default forward to "Welcome" action -->
        <!-- Demonstrates using index.jsp to forward -->
        <forward
            name="index"
            path="/pages/index.jsp"/>  
    </global-forwards>


<!-- =========================================== Action Mapping Definitions -->

    <action-mappings>      
        <!-- 1 select language action -->         
            <action    path="/SelectLanguageAction"
              type="com.nova.colimas.web.action.SelectLanguageAction"
              name="SelectLanguageForm"
              scope="request">
            </action>
                …
    </action-mappings>
      


3 jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/tags/struts-bean" divfix="bean"%>
<%@ taglib uri="/tags/struts-html" divfix="html"%>
<%@ taglib uri="/tags/struts-logic" divfix="logic"%>

<html:html>
<Title><bean:message key="index.jsp.welcome"/></Title>
<body>
<logic:divsent name="user">
        <H3>Welcome <bean:write name="LoginForm" property="userID" />!</H3>
</logic:divsent>
<logic:notPresent scope="session" name="user">
        <H3>Welcome Colimas!</H3>
</logic:notPresent>
<html:errors />
<html:form action="/SelectLanguageAction.do">
       <html:select property="language">
                <html:option value="0">中文</html:option>
                <html:option value="1">日本語</html:option>
                <html:option value="2">English</html:option>              
       </html:select>
        <html:submit>Select</html:submit>
</html:form>


<html:form action="/LoginAction.do">
        <p><bean:message key="index.jsp.userid"/><input type="text" name="userID" value="tyrone1979" /><br>
        <bean:message key="index.jsp.pass"/><input type="password" name="password" value="197913"/><br>
        <html:submit><bean:message key="index.jsp.login"/></html:submit>
        </p>
</html:form>

</body>
</html:html>


<bean:message key="index.jsp.welcome"/>引用資源文件的index.jsp.welcome屬性
SelectLanguageAction.do調用Action實現語言轉換。

4 Action

package com.nova.colimas.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;
//import org.apache.struts.upload.FormFile;
import com.nova.colimas.web.form.SelectLanguageForm;
import org.apache.struts.Globals;
import java.util.Locale;

public class SelectLanguageAction extends Action {
        public ActionForward execute(ActionMapping mapping,
                         ActionForm form,
                         HttpServletRequest request,
                         HttpServletResponse response)
        throws Exception{
                SelectLanguageForm myform=(SelectLanguageForm)form;
                String lan=myform.getLanguage();
                switch((new Integer(lan)).intValue()){
                case 0 :
                        request.getSession().setAttribute(Globals.LOCALE_KEY,Locale.CHINA);
                        break;
                case 1:
                        request.getSession().setAttribute(Globals.LOCALE_KEY, Locale.JAPAN);
                        break;
                case 2:
                        request.getSession().setAttribute(Globals.LOCALE_KEY, Locale.ENGLISH);
                        break;
                default:
                        request.getSession().setAttribute(Globals.LOCALE_KEY, Locale.ENGLISH);
                        break;
                }
                        return mapping.findForward("index");
        }
}
Form
/*
* Created on 2005/06/18
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.nova.colimas.web.form;

import org.apache.struts.action.ActionForm;

/**
* @author tyrone
**/
public class SelectLanguageForm extends ActionForm {

        private String language;

        public void Reset() {
                this.language="";
                return;
        }

        /**
         * @return Returns the Language.
         */
        public String getLanguage() {
                return language;
        }
        /**
         * @param language The Language to set.
         */
        public void setLanguage(String property1) {
                this.language = property1;
        }
}


結果
1 IE默認語言為中文:



鐵猴 2009-11-01 12:37 發表評論
]]>
Eclipse 3.4下J2ME開發環境的配置http://www.tkk7.com/xlth2006/archive/2009/10/25/299688.html鐵猴鐵猴Sun, 25 Oct 2009 11:54:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/25/299688.htmlhttp://www.tkk7.com/xlth2006/comments/299688.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/25/299688.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/299688.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/299688.html·               配置Eclipse

  1. 下載JDK:

從sun的官網http://java.sun.com/javase/downloads/?intcmp=1281下載JDK,當前最新版本是jdk-6u10-windows-i586-p.exe,這個是正式版的。

  1. 下載WTK:

同時在sun的網站http://java.sun.com/products/sjwtoolkit/zh_download-2_5_2.html下載WTK,當前最新版本是sun_java_wireless_toolkit-2_5_2-ml-windows.exe。

  1. 安裝JDK和WTK:

先安裝JDK再安裝WTK,我的安裝路徑是:D:"Java"jdk1.6.0_10和D:"Java"WTK2.5.2

  1. 下載eclipse:

從eclipse的官網 http://www.eclipse.org/downloads/下載eclipse,我用的是:eclipse-java-ganymede-SR1-win32.zip,解壓到:XX:"eclipse

  1. 下載eclipseme:

從eclipseme的官網   http://sourceforge.net/project/showfiles.php?group_id=86829下載eclipseme.當前最新版本是eclipseeclipseme.feature_1.7.9_site.zip

  1. 配置eclipse:

到 “首選項”找到,Java—>調試,將“發生未不捕獲到的異常時暫掛執行”與“在發生編譯錯誤時暫掛執行”這兩個選項調為“未選中”狀態,再把下面的調試器超時(毫秒)的右側數值設置為15000

  1. 配置eclipseME:

運行eclipse,配置自己學習的工作路徑,選擇 幫助—>軟件更新—>查找并安裝—>搜索要安裝的新功能部件,選擇 新建已歸檔的站點,選擇eclipseme.feature_1.7.9_site.zip文件,安裝,重啟eclipse

  1. 配置WTK:

選擇 首選項—>J2ME—>Device Management—>Import 在Specify search directory下,選擇你所裝的WTK模擬器的目錄;選擇 Refresh ,后按完成,使用DefaultColorPhone為默認模式,這時已為eclipse配置上了模擬器

  1. 下載ProGuard:

需要使用插件ProGuard,從ProGuard的官網下載ProGuard,當前的最新版本是:proguard4.3beta2.tar.gz,解壓到:XX:"proguard4.3

  1. 配置ProGuard:

到 Eclipse的“首選項”找到,J2ME—>Packaging—>obfuscation,在Proguard Root Directory右邊的框中,選擇剛才解壓的proguard4.3的文件夾(XX:"proguard4.3),點擊應用,這時為eclipse配置上了混淆器

  1. 配置完畢

·               使用eclipse進行J2ME開發

  1. 新建 J2ME下的J2ME Midlet Suite,填寫項目名,下一步,完成
  2. 新建 J2ME下的J2ME Midlet,填寫名稱,完成
  3. 點擊運行,新建一個Wireless Toolkit Emulator的運行配置,運行,出現手機樣式,運行成功


鐵猴 2009-10-25 19:54 發表評論
]]>
webservice調用例子http://www.tkk7.com/xlth2006/archive/2009/10/22/299266.html鐵猴鐵猴Wed, 21 Oct 2009 23:50:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/22/299266.htmlhttp://www.tkk7.com/xlth2006/comments/299266.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/22/299266.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/299266.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/299266.html

import java.net.URL;
import java.util.Vector;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.encoding.soapenc.BeanSerializer;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
import org.apache.soap.transport.http.SOAPHTTPConnection;
import org.apache.soap.util.xml.QName;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import oss.util.debug.LogHome;

public class GisWebService{
 
 public static String getStringGisWebService(String ajfBm, String zjfBm, String aodfBm,String zodfBm) throws Exception {
  String strUrl = "   String strTargetURL = "http://java.sun.com/xml/ns/jax-rpc/ri/config";//
  String soapAction = "      URL url = new URL(strUrl);
     SOAPMappingRegistry smr = new SOAPMappingRegistry();
     BeanSerializer beanSer = new BeanSerializer();
     smr.mapTypes(Constants.NS_URI_SOAP_ENC,new QName("","Result"),null,null,beanSer);
     Call call = new Call();
     SOAPHTTPConnection st = new SOAPHTTPConnection();
     call.setSOAPTransport(st);
     call.setSOAPMappingRegistry(smr);
     call.setTargetObjectURI(strTargetURL);
     call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
     call.setParams(createCondition(ajfBm,zjfBm,aodfBm,zodfBm));
     call.setMethodName("WSEncrypt"); //調用WEBSERVICE方法名
     Response resp;
     try
     {
       call.setTimeout(3000);
       resp = call.invoke(url,soapAction);
     }
     catch(SOAPException e)
     {
       throw new Exception("調用接口出錯!URL="+strUrl+"\n"+e.getMessage());
     }
     LogHome.getLog().info("調用成功,開始接收返回信息!");

     return returnValue(resp);
 }
 
 public static String returnValue(Response resp) throws Exception {
  if(resp.generatedFault()) {
        Fault fault = resp.getFault();
        String code = fault.getFaultCode();
        String desc = fault.getFaultString();
        LogHome.getLog().info("Fault code:"+code+":"+desc);
        Vector v = fault.getDetailEntries();
        int cnt = v.size();
        for(int i = 0;i<cnt;i++)
        {
          Element n = (Element)v.elementAt(i);
          Node nd = n.getFirstChild();
          LogHome.getLog().info("Each element:"+n.getNodeName()+":"+nd.getNodeValue());
        }
        throw new Exception("調用接口時出錯,Fault code:"+code+":"+desc);
      }
      else
      {
        Parameter ret = resp.getReturnValue();
        String returnXML = (String)ret.getValue();
        LogHome.getLog().info(returnXML);
        return returnXML;
      }
 }
 
 public static  Vector<Parameter> createCondition(String ajfBm,String zjfBm,String aodfBm,String zodfBm) {
   Vector<Parameter> params = new Vector<Parameter>();
     params.addElement(new Parameter("AjfBm",String.class,ajfBm,null));
     params.addElement(new Parameter("ZjfBm",String.class,zjfBm,null));
     params.addElement(new Parameter("AodfBm",String.class,aodfBm,null));
     params.addElement(new Parameter("ZodfBm",String.class,zodfBm,null));
     return params;
 }
 
}



鐵猴 2009-10-22 07:50 發表評論
]]>
JAVA中Date轉換大全http://www.tkk7.com/xlth2006/archive/2009/10/17/298686.html鐵猴鐵猴Sat, 17 Oct 2009 07:16:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/17/298686.htmlhttp://www.tkk7.com/xlth2006/comments/298686.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/17/298686.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/298686.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/298686.htmlpublic static Date getNowDate() {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  String dateString = formatter.format(currentTime);

  ParsePosition pos = new ParsePosition(8);

  Date currentTime_2 = formatter.parse(dateString, pos);

  return currentTime_2;

 }

 /**

  * 獲取現在時間

  *

  * @return返回短時間格式 yyyy-MM-dd

  */

 public static Date getNowDateShort() {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

  String dateString = formatter.format(currentTime);

  ParsePosition pos = new ParsePosition(8);

  Date currentTime_2 = formatter.parse(dateString, pos);

  return currentTime_2;

 }

 /**

  * 獲取現在時間

  *

  * @return返回字符串格式 yyyy-MM-dd HH:mm:ss

  */

 public static String getStringDate() {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  String dateString = formatter.format(currentTime);

  return dateString;

 }

 /**

  * 獲取現在時間

  *

  * @return 返回短時間字符串格式yyyy-MM-dd

  */

 public static String getStringDateShort() {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

  String dateString = formatter.format(currentTime);

  return dateString;

 }

 /**

  * 獲取時間 小時:分;秒 HH:mm:ss

  *

  * @return

  */

 public static String getTimeShort() {

  SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");

  Date currentTime = new Date();

  String dateString = formatter.format(currentTime);

  return dateString;

 }

 /**

  * 將長時間格式字符串轉換為時間 yyyy-MM-dd HH:mm:ss

  *

  * @param strDate

  * @return

  */

 public static Date strToDateLong(String strDate) {

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  ParsePosition pos = new ParsePosition(0);

  Date strtodate = formatter.parse(strDate, pos);

  return strtodate;

 }

 /**

  * 將長時間格式時間轉換為字符串 yyyy-MM-dd HH:mm:ss

  *

  * @param dateDate

  * @return

  */

 public static String dateToStrLong(java.util.Date dateDate) {

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  String dateString = formatter.format(dateDate);

  return dateString;

 }

 /**

  * 將短時間格式時間轉換為字符串 yyyy-MM-dd

  *

  * @param dateDate

  * @param k

  * @return

  */

 public static String dateToStr(java.util.Date dateDate) {

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

  String dateString = formatter.format(dateDate);

  return dateString;

 }

 /**

  * 將短時間格式字符串轉換為時間 yyyy-MM-dd

  *

  * @param strDate

  * @return

  */

 public static Date strToDate(String strDate) {

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

  ParsePosition pos = new ParsePosition(0);

  Date strtodate = formatter.parse(strDate, pos);

  return strtodate;

 }

 /**

  * 得到現在時間

  *

  * @return

  */

 public static Date getNow() {

  Date currentTime = new Date();

  return currentTime;

 }

 /**

  * 提取一個月中的最后一天

  *

  * @param day

  * @return

  */

 public static Date getLastDate(long day) {

  Date date = new Date();

  long date_3_hm = date.getTime() - 3600000 * 34 * day;

  Date date_3_hm_date = new Date(date_3_hm);

  return date_3_hm_date;

 }

 /**

  * 得到現在時間

  *

  * @return 字符串 yyyyMMdd HHmmss

  */

 public static String getStringToday() {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");

  String dateString = formatter.format(currentTime);

  return dateString;

 }

 /**

  * 得到現在小時

  */

 public static String getHour() {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  String dateString = formatter.format(currentTime);

  String hour;

  hour = dateString.substring(11, 13);

  return hour;

 }

 /**

  * 得到現在分鐘

  *

  * @return

  */

 public static String getTime() {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  String dateString = formatter.format(currentTime);

  String min;

  min = dateString.substring(14, 16);

  return min;

 }

 /**

  * 根據用戶傳入的時間表示格式,返回當前時間的格式 如果是yyyyMMdd,注意字母y不能大寫。

  *

  * @param sformat

  *            yyyyMMddhhmmss

  * @return

  */

 public static String getUserDate(String sformat) {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat(sformat);

  String dateString = formatter.format(currentTime);

  return dateString;

 }

 /**

  * 二個小時時間間的差值,必須保證二個時間都是"HH:MM"的格式,返回字符型的分鐘

  */

 public static String getTwoHour(String st1, String st2) {

  String[] kk = null;

  String[] jj = null;

  kk = st1.split(":");

  jj = st2.split(":");

  if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0]))

   return "0";

  else {

   double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1]) / 60;

   double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1]) / 60;

   if ((y - u) > 0)

    return y - u + "";

   else

    return "0";

  }

 }

 /**

  * 得到二個日期間的間隔天數

  */

 public static String getTwoDay(String sj1, String sj2) {

  SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");

  long day = 0;

  try {

   java.util.Date date = myFormatter.parse(sj1);

   java.util.Date mydate = myFormatter.parse(sj2);

   day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);

  } catch (Exception e) {

   return "";

  }

  return day + "";

 }

 /**

  * 時間前推或后推分鐘,其中JJ表示分鐘.

  */

 public static String getPreTime(String sj1, String jj) {

  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  String mydate1 = "";

  try {

   Date date1 = format.parse(sj1);

   long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60;

   date1.setTime(Time * 1000);

   mydate1 = format.format(date1);

  } catch (Exception e) {

  }

  return mydate1;

 }

 /**

  * 得到一個時間延后或前移幾天的時間,nowdate為時間,delay為前移或后延的天數

  */

 public static String getNextDay(String nowdate, String delay) {

  try{

  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

  String mdate = "";

  Date d = strToDate(nowdate);

  long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24 * 60 * 60;

  d.setTime(myTime * 1000);

  mdate = format.format(d);

  return mdate;

  }catch(Exception e){

   return "";

  }

 }

 /**

  * 判斷是否潤年

  *

  * @param ddate

  * @return

  */

 public static boolean isLeapYear(String ddate) {

  /**

   * 詳細設計: 1.被400整除是閏年,否則: 2.不能被4整除則不是閏年 3.能被4整除同時不能被100整除則是閏年

   * 3.能被4整除同時能被100整除則不是閏年

   */

  Date d = strToDate(ddate);

  GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();

  gc.setTime(d);

  int year = gc.get(Calendar.YEAR);

  if ((year % 400) == 0)

   return true;

  else if ((year % 4) == 0) {

   if ((year % 100) == 0)

    return false;

   else

    return true;

  } else

   return false;

 }

 /**

  * 返回美國時間格式 26 Apr 2006

  *

  * @param str

  * @return

  */

 public static String getEDate(String str) {

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

  ParsePosition pos = new ParsePosition(0);

  Date strtodate = formatter.parse(str, pos);

  String j = strtodate.toString();

  String[] k = j.split(" ");

  return k[2] + k[1].toUpperCase() + k[5].substring(2, 4);

 }

 /**

  * 獲取一個月的最后一天

  *

  * @param dat

  * @return

  */

 public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd

  String str = dat.substring(0, 8);

  String month = dat.substring(5, 7);

  int mon = Integer.parseInt(month);

  if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 || mon == 10 || mon == 12) {

   str += "31";

  } else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {

   str += "30";

  } else {

   if (isLeapYear(dat)) {

    str += "29";

   } else {

    str += "28";

   }

  }

  return str;

 }

 /**

  * 判斷二個時間是否在同一個周

  *

  * @param date1

  * @param date2

  * @return

  */

 public static boolean isSameWeekDates(Date date1, Date date2) {

  Calendar cal1 = Calendar.getInstance();

  Calendar cal2 = Calendar.getInstance();

  cal1.setTime(date1);

  cal2.setTime(date2);

  int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR);

  if (0 == subYear) {

   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))

    return true;

  } else if (1 == subYear && 11 == cal2.get(Calendar.MONTH)) {

   // 如果12月的最后一周橫跨來年第一周的話則最后一周即算做來年的第一周

   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))

    return true;

  } else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH)) {

   if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2.get(Calendar.WEEK_OF_YEAR))

    return true;

  }

  return false;

 }

 /**

  * 產生周序列,即得到當前時間所在的年度是第幾周

  *

  * @return

  */

 public static String getSeqWeek() {

  Calendar c = Calendar.getInstance(Locale.CHINA);

  String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR));

  if (week.length() == 1)

   week = "0" + week;

  String year = Integer.toString(c.get(Calendar.YEAR));

  return year + week;

 }

 /**

  * 獲得一個日期所在的周的星期幾的日期,如要找出2002年2月3日所在周的星期一是幾號

  *

  * @param sdate

  * @param num

  * @return

  */

 public static String getWeek(String sdate, String num) {

  // 再轉換為時間

  Date dd = VeDate.strToDate(sdate);

  Calendar c = Calendar.getInstance();

  c.setTime(dd);

  if (num.equals("1")) // 返回星期一所在的日期

   c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);

  else if (num.equals("2")) // 返回星期二所在的日期

   c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);

  else if (num.equals("3")) // 返回星期三所在的日期

   c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);

  else if (num.equals("4")) // 返回星期四所在的日期

   c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);

  else if (num.equals("5")) // 返回星期五所在的日期

   c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);

  else if (num.equals("6")) // 返回星期六所在的日期

   c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);

  else if (num.equals("0")) // 返回星期日所在的日期

   c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

  return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());

 }

 /**

  * 根據一個日期,返回是星期幾的字符串

  *

  * @param sdate

  * @return

  */

 public static String getWeek(String sdate) {

  // 再轉換為時間

  Date date = VeDate.strToDate(sdate);

  Calendar c = Calendar.getInstance();

  c.setTime(date);

  // int hour=c.get(Calendar.DAY_OF_WEEK);

  // hour中存的就是星期幾了,其范圍 1~7

  // 1=星期日 7=星期六,其他類推

  return new SimpleDateFormat("EEEE").format(c.getTime());

 }

 public static String getWeekStr(String sdate){

  String str = "";

  str = VeDate.getWeek(sdate);

  if("1".equals(str)){

   str = "星期日";

  }else if("2".equals(str)){

   str = "星期一";

  }else if("3".equals(str)){

   str = "星期二";

  }else if("4".equals(str)){

   str = "星期三";

  }else if("5".equals(str)){

   str = "星期四";

  }else if("6".equals(str)){

   str = "星期五";

  }else if("7".equals(str)){

   str = "星期六";

  }

  return str;

 }

 /**

  * 兩個時間之間的天數

  *

  * @param date1

  * @param date2

  * @return

  */

 public static long getDays(String date1, String date2) {

  if (date1 == null || date1.equals(""))

   return 0;

  if (date2 == null || date2.equals(""))

   return 0;

  // 轉換為標準時間

  SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");

  java.util.Date date = null;

  java.util.Date mydate = null;

  try {

   date = myFormatter.parse(date1);

   mydate = myFormatter.parse(date2);

  } catch (Exception e) {

  }

  long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);

  return day;

 }

 /**

  * 形成如下的日歷 , 根據傳入的一個時間返回一個結構 星期日 星期一 星期二 星期三 星期四 星期五 星期六 下面是當月的各個時間

  * 此函數返回該日歷第一行星期日所在的日期

  *

  * @param sdate

  * @return

  */

 public static String getNowMonth(String sdate) {

  // 取該時間所在月的一號

  sdate = sdate.substring(0, 8) + "01";

  // 得到這個月的1號是星期幾

  Date date = VeDate.strToDate(sdate);

  Calendar c = Calendar.getInstance();

  c.setTime(date);

  int u = c.get(Calendar.DAY_OF_WEEK);

  String newday = VeDate.getNextDay(sdate, (1 - u) + "");

  return newday;

 }

 /**

  * 取得數據庫主鍵 生成格式為yyyymmddhhmmss+k位隨機數

  *

  * @param k

  *            表示是取幾位隨機數,可以自己定

  */

 public static String getNo(int k) {

  return getUserDate("yyyyMMddhhmmss") + getRandom(k);

 }

 /**

  * 返回一個隨機數

  *

  * @param i

  * @return

  */

 public static String getRandom(int i) {

  Random jjj = new Random();

  // int suiJiShu = jjj.nextInt(9);

  if (i == 0)

   return "";

  String jj = "";

  for (int k = 0; k < i; k++) {

   jj = jj + jjj.nextInt(9);

  }

  return jj;

 }

 /**

  *

  * @param args

  */

 public static boolean RightDate(String date) {

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

  ;

  if (date == null)

   return false;

  if (date.length() > 10) {

   sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

  } else {

   sdf = new SimpleDateFormat("yyyy-MM-dd");

  }

  try {

   sdf.parse(date);

  } catch (ParseException pe) {

   return false;

  }

  return true;

 }

 /***************************************************************************

  * //nd=1表示返回的值中包含年度 //yf=1表示返回的值中包含月份 //rq=1表示返回的值中包含日期 //format表示返回的格式 1

  * 以年月日中文返回 2 以橫線-返回 // 3 以斜線/返回 4 以縮寫不帶其它符號形式返回 // 5 以點號.返回

  **************************************************************************/

 public static String getStringDateMonth(String sdate, String nd, String yf, String rq, String format) {

  Date currentTime = new Date();

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

  String dateString = formatter.format(currentTime);

  String s_nd = dateString.substring(0, 4); // 年份

  String s_yf = dateString.substring(5, 7); // 月份

  String s_rq = dateString.substring(8, 10); // 日期

  String sreturn = "";

  roc.util.MyChar mc = new roc.util.MyChar();

  if (sdate == null || sdate.equals("") || !mc.Isdate(sdate)) { // 處理空值情況

   if (nd.equals("1")) {

    sreturn = s_nd;

    // 處理間隔符

    if (format.equals("1"))

     sreturn = sreturn + "年";

    else if (format.equals("2"))

     sreturn = sreturn + "-";

    else if (format.equals("3"))

     sreturn = sreturn + "/";

    else if (format.equals("5"))

     sreturn = sreturn + ".";

   }

   // 處理月份

   if (yf.equals("1")) {

    sreturn = sreturn + s_yf;

    if (format.equals("1"))

     sreturn = sreturn + "月";

    else if (format.equals("2"))

     sreturn = sreturn + "-";

    else if (format.equals("3"))

     sreturn = sreturn + "/";

    else if (format.equals("5"))

     sreturn = sreturn + ".";

   }

   // 處理日期

   if (rq.equals("1")) {

    sreturn = sreturn + s_rq;

    if (format.equals("1"))

     sreturn = sreturn + "日";

   }

  } else {

   // 不是空值,也是一個合法的日期值,則先將其轉換為標準的時間格式

   sdate = roc.util.RocDate.getOKDate(sdate);

   s_nd = sdate.substring(0, 4); // 年份

   s_yf = sdate.substring(5, 7); // 月份

   s_rq = sdate.substring(8, 10); // 日期

   if (nd.equals("1")) {

    sreturn = s_nd;

    // 處理間隔符

    if (format.equals("1"))

     sreturn = sreturn + "年";

    else if (format.equals("2"))

     sreturn = sreturn + "-";

    else if (format.equals("3"))

     sreturn = sreturn + "/";

    else if (format.equals("5"))

     sreturn = sreturn + ".";

   }

   // 處理月份

   if (yf.equals("1")) {

    sreturn = sreturn + s_yf;

    if (format.equals("1"))

     sreturn = sreturn + "月";

    else if (format.equals("2"))

     sreturn = sreturn + "-";

    else if (format.equals("3"))

     sreturn = sreturn + "/";

    else if (format.equals("5"))

     sreturn = sreturn + ".";

   }

   // 處理日期

   if (rq.equals("1")) {

    sreturn = sreturn + s_rq;

    if (format.equals("1"))

     sreturn = sreturn + "日";

   }

  }

  return sreturn;

 }

 public static String getNextMonthDay(String sdate, int m) {

  sdate = getOKDate(sdate);

  int year = Integer.parseInt(sdate.substring(0, 4));

  int month = Integer.parseInt(sdate.substring(5, 7));

  month = month + m;

  if (month < 0) {

   month = month + 12;

   year = year - 1;

  } else if (month > 12) {

   month = month - 12;

   year = year + 1;

  }

  String smonth = "";

  if (month < 10)

   smonth = "0" + month;

  else

   smonth = "" + month;

  return year + "-" + smonth + "-10";

 }

 public static String getOKDate(String sdate) {

  if (sdate == null || sdate.equals(""))

   return getStringDateShort();

  if (!VeStr.Isdate(sdate)) {

   sdate = getStringDateShort();

  }

  // 將“/”轉換為“-”

  sdate = VeStr.Replace(sdate, "/", "-");

  // 如果只有8位長度,則要進行轉換

  if (sdate.length() == 8)

   sdate = sdate.substring(0, 4) + "-" + sdate.substring(4, 6) + "-" + sdate.substring(6, 8);

  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

  ParsePosition pos = new ParsePosition(0);

  Date strtodate = formatter.parse(sdate, pos);

  String dateString = formatter.format(strtodate);

  return dateString;

 }

 public static void main(String[] args) throws Exception {

  try {

   //System.out.print(Integer.valueOf(getTwoDay("2006-11-03 12:22:10", "2006-11-02 11:22:09")));

  } catch (Exception e) {

   throw new Exception();

  }

  //System.out.println("sss");

 }

}   



鐵猴 2009-10-17 15:16 發表評論
]]>
Tomcat 配置 -- 打開中文文件名的附件http://www.tkk7.com/xlth2006/archive/2009/10/12/297952.html鐵猴鐵猴Mon, 12 Oct 2009 10:59:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/12/297952.htmlhttp://www.tkk7.com/xlth2006/comments/297952.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/12/297952.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/297952.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/297952.html
1<Connector port="8080" protocol="HTTP/1.1"    
2           connectionTimeout="20000"    
3           redirectPort="8443" URIEncoding="GBK"/>   

將編碼格式改為UTF-8就可以了:
<Connector port="8080" protocol="HTTP/1.1"    
           connectionTimeout
="20000"    
           redirectPort
="8443" URIEncoding="UTF-8"/>   


鐵猴 2009-10-12 18:59 發表評論
]]>
防止JSP頁面緩存http://www.tkk7.com/xlth2006/archive/2009/10/05/297241.html鐵猴鐵猴Mon, 05 Oct 2009 04:09:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/05/297241.htmlhttp://www.tkk7.com/xlth2006/comments/297241.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/05/297241.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/297241.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/297241.html <%
       // 將過期日期設置為一個過去時間

        response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");

        // 設置 HTTP/1.1 no-cache 頭
        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");

        // 設置 IE 擴展 HTTP/1.1 no-cache headers, 用戶自己添加
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");

        // 設置標準 HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");
%>


鐵猴 2009-10-05 12:09 發表評論
]]>
把class文件打成jar包的命令http://www.tkk7.com/xlth2006/archive/2009/10/05/297237.html鐵猴鐵猴Mon, 05 Oct 2009 03:06:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/05/297237.htmlhttp://www.tkk7.com/xlth2006/comments/297237.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/05/297237.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/297237.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/297237.html 在文件所在目錄下,
D:\>jar cvf jspsmart.jar jspsmart 

鐵猴 2009-10-05 11:06 發表評論
]]>
java創建TXT文件并進行讀、寫、修改操作 http://www.tkk7.com/xlth2006/archive/2009/10/04/297198.html鐵猴鐵猴Sun, 04 Oct 2009 09:17:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/04/297198.htmlhttp://www.tkk7.com/xlth2006/comments/297198.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/04/297198.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/297198.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/297198.html閱讀全文

鐵猴 2009-10-04 17:17 發表評論
]]>
徹底解決jspsmartupload中文名文件下載和下載文件內容亂碼問題http://www.tkk7.com/xlth2006/archive/2009/10/01/297088.html鐵猴鐵猴Thu, 01 Oct 2009 07:15:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/01/297088.htmlhttp://www.tkk7.com/xlth2006/comments/297088.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/01/297088.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/297088.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/297088.html徹底解決中文名文件下載和下載文件內容亂碼問題!!!!! 之前,寫過一個Download.jsp文件,可以解決下載文件亂碼問題(諸如:DOC,XSL文件等等).
后來發現,遇到中文名的文件的時候,文件下載將會報錯~~~~
今天,通過改寫原Download.jsp文件已經徹底解決了這個問題~
現在,把一整套的文件上傳下載的方法給貼出來~~~以便大家借鑒!~!~!~!~! 
作者:古埃及法老
-------------------------------------------------------------------------------------------------------------------
測試環境:WEBLOGIC 8.1,WIN XP SP4,IE 6.0
-----------------------------------------------------
文件上傳:
-----------------------------------------
準備工作:導入著名的SmartUpload.jar組件包
upload.jsp文件
---------------------------------------------------------
<%@ page contentType="text/html; charset=gb2312" %>
<%
request.setCharacterEncoding("gb2312"); // 這句話很重要,否則遇到中文就出錯~
%>
<HTML><HEAD><TITLE>上傳</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
</HEAD>
<BODY leftMargin=0 topMargin=0>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#DEE7EF">
   <tr>
     <td align="center">
       <FORM action="upload_ok.jsp" method=post name="Upload" enctype="multipart/form-data">
         <br>
         請輸入附件文件的所在路徑<FONT color=red> * </FONT>為必填項目<br>
         <br>
         <TABLE width="317" border=0 cellPadding=0>
           <TBODY>
             <TR>
               <TD align=right valign=middle nowrap>附件路徑:</TD>
               <TD><input type="file" name="file" style="border: 1px #FFFFFF solid;background:#efefef" > <FONT color=red>*</FONT></TD>
             </TR>
             <TR align="center">
               <TD height=60 colspan="2" valign=middle nowrap> <INPUT style="height:22px" name=B1 type=submit value=" 確 定 " >
<INPUT style="height:22px" name=B2 type=reset value=" 取 消 " >
               </TD>
             </TR>
           </TBODY>
         </TABLE>
       </FORM>
</td>
   </tr>
</table>
</BODY></HTML>
---------------------------------------------------------
upload_ok.jsp文件
---------------------------------------------------------
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="com.jspsmart.upload.*" %>
<HTML><HEAD><TITLE>上傳成功!</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
</HEAD>
<BODY leftMargin=0 topMargin=0>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<table width="80%"   border="0" cellpadding="0" cellspacing="0" bgcolor="#DEE7EF">
   <tr>
     <td align="center">
<%
int count=0;
String fileName = null;
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
if (!myFile.isMissing()) {
   //String ext=myFile.getFileExt();//得到后綴  
   fileName = myFile.getFileName();
             myFile.saveAs("/files/" + fileName);//你要存放文件所在文件夾的相對路徑
      out.println("文件:<b>"+fileName+"</b>上傳成功!<br>文件大小:" + myFile.getSize() + "kb<BR>");
      }
%>
</BODY></HTML>
---------------------------------------------------------

文件下載:
-----------------------------------------
文件的超連接寫法范例:
<% String fname ="中文測試.xsl"; //假設你的文件名是:中文測試.xsl
%>
<A target="_blank" href="Download.jsp?filename=<%=fname%>">下 載</A>
文件的超連接寫法范例-2 重新用utf-8對文件名編碼:
<%@ page contentType="text/html;charset=gb2312" session="true"%>
<%   String name=java.net.URLEncoder.encode("世界文化.doc","UTF-8"));%>   <a href="c:\<%=name%>">世界文化.doc</a>

Download.jsp文件
---------------------------------------------------------
<%
   java.io.BufferedInputStream bis=null;
   java.io.BufferedOutputStream   bos=null;
try{
String filename=request.getParameter("filename");
              filename=new String(filename.getBytes("iso8859-1"),"gb2312");
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gb2312"),"iso8859-1"));
bis =new java.io.BufferedInputStream(new java.io.FileInputStream(config.getServletContext().getRealPath("files/" + filename)));
bos=new java.io.BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
   bos.write(buff,0,bytesRead);
}
}
catch(Exception e){
e.printStackTrace();
}
finally {
if (bis != null)bis.close();
if (bos != null)bos.close();
}
%> 
 



鐵猴 2009-10-01 15:15 發表評論
]]>
文件上傳:用O’Reilly公司的cos實現文件上傳 http://www.tkk7.com/xlth2006/archive/2009/10/01/297085.html鐵猴鐵猴Thu, 01 Oct 2009 06:15:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/10/01/297085.htmlhttp://www.tkk7.com/xlth2006/comments/297085.htmlhttp://www.tkk7.com/xlth2006/archive/2009/10/01/297085.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/297085.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/297085.html
index.html文件:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>無標題文檔</title>
</head>

<body>
<!-- enctype的值很重要,upload.jsp為處理上傳的jsp-->
<form name="form1"  method="post" enctype="multipart/form-data" 
action
="upload.jsp">
<p>
  
<input name="file1" type="file">
</p>
<p>
  
<input name="file2" type="file">
</p>
<p>  <input name="file3" type="file">
</p>
<p>
  
<input type="submit" name="Submit" value="上傳">
</p>
</form >

</body>
</html> 

upload.jsp文件 :
<%@page import="java.io.*"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@page import="com.oreilly.servlet.multipart.CoverFileRenamePolicy"%>
<%@page contentType="text/html; charset=gb2312" %>
<%
//文件上傳后,保存在c:\\upload
String saveDirectory ="c:\\upload";
//每個文件最大5m,最多3個文件,所以
int maxPostSize =3 * 5 * 1024 * 1024 ;
//response的編碼為"gb2312",同時采用缺省的文件名沖突解決策略,實現上傳
//就這一句就完成上傳了,真是很爽
MultipartRequest multi 
= new MultipartRequest(request, saveDirectory, maxPostSize,"gb2312");

//輸出反饋信息
 Enumeration files 
= multi.getFileNames();
     
while (files.hasMoreElements()) {
        System.err.println(
"ccc");
       
String name = (String)files.nextElement();
       File f 
= multi.getFile(name);
       
if(f!=null){
         
String fileName = multi.getFilesystemName(name);
         
String lastFileName= saveDirectory+"\\" + fileName;
         out.println(
"上傳的文件:"+lastFileName);
         out.println(
"<hr>");

       }
     }

%>


鐵猴 2009-10-01 14:15 發表評論
]]>
更改myeclipse打開jsp頁面的關聯方式為MyEclipse JSP Editor 解決myEclipse打開JSP時要等上好幾秒的問題http://www.tkk7.com/xlth2006/archive/2009/09/28/296735.html鐵猴鐵猴Mon, 28 Sep 2009 02:13:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/09/28/296735.htmlhttp://www.tkk7.com/xlth2006/comments/296735.htmlhttp://www.tkk7.com/xlth2006/archive/2009/09/28/296735.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/296735.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/296735.htmlmyEclipse打開JSP時老是要等上好幾秒原因?

這個問題的確很煩人,其實都是MyEclipse的“自作聰明”的結果(它默認用Visual Designer來打開的),進行下列設置即可有效緩解之。

1. 要么右鍵單擊文件,選擇 Open With -》 MyEclipse JSP Editor 打開,這樣不會采用可視化的打開,耗資源少,自動提示也非常快。

2. 要么采取一勞永逸的方法 Window -》 Preferences -》 General -》 Editors -》 File Associations
將默認打*.jsp的editor關聯設置為MyEclipse JSP Editor .

jsp頁面提示功能卡的解決方法
上一篇文章只是解決單個工程表面問題,也就是提示的時候用了我自己的這個servlet-api.jar這個jar包,所以會解決問題,如果你不想加入jar包,那么請看以下說明:      
最終原因為:
新建的工程中加入了j2ee1.4 lib庫,庫中的javax.servelet.jar這個包中的javadoc location 位置設置的官方網站。這樣你每次提示的時候都要去官方網站去找doc所以導致myeclipse會很卡,當禁用網卡或者拔掉網線的時候,就不會在卡了。
http://hanbao.javaeye.com/blog/244272
最終解決方法:
菜單 [Window]->[Preferences]->[MyEclipse]->[JavaEnterprise Project]->[Library Sets] [J2EE1.4]和[J2EE1.3]下的javax.servelet.jar
點開樹 選擇[javadoc location]這個節點 雙擊 然后在對話框中,把這個 那個地址去掉為空或者選擇你本地javadoc地址即可解決 jsp 自動提示 卡 慢 的問題。



鐵猴 2009-09-28 10:13 發表評論
]]>
讓JSP頁面不緩存[設置JSP頁面立即過期] http://www.tkk7.com/xlth2006/archive/2009/09/25/296475.html鐵猴鐵猴Fri, 25 Sep 2009 15:20:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/09/25/296475.htmlhttp://www.tkk7.com/xlth2006/comments/296475.htmlhttp://www.tkk7.com/xlth2006/archive/2009/09/25/296475.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/296475.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/296475.html在JSP頁面的前面加上:

<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
%>



鐵猴 2009-09-25 23:20 發表評論
]]>
Jsp頁面實現文件上傳http://www.tkk7.com/xlth2006/archive/2009/09/22/295938.html鐵猴鐵猴Tue, 22 Sep 2009 00:26:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/09/22/295938.htmlhttp://www.tkk7.com/xlth2006/comments/295938.htmlhttp://www.tkk7.com/xlth2006/archive/2009/09/22/295938.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/295938.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/295938.html名稱:jsp頁面上傳類

特點

  1. 可以多文件上傳;
  2. 返回上傳后的文件名;
  3. form表單中的其他參數也可以得到。

先貼上傳類,JspFileUpload

package com.vogoal.util;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
/*
* vogoalAPI 1.0
* Auther SinNeR@blueidea.com
* by vogoal.com
* mail: vogoals@hotmail.com
*/
/**
* JSP上傳文件類
*
* @author SinNeR
* @version 1.0
*/
public class JspFileUpload {
    /** request對象 */
    private HttpServletRequest request = null;
    /** 上傳文件的路徑 */
    private String uploadPath = null;
    /** 每次讀取得字節的大小 */
    private static int BUFSIZE = 1024 * 8;
    /** 存儲參數的Hashtable */
    private Hashtable paramHt = new Hasptable();
    /** 存儲上傳的文件的文件名的ArrayList */
    private ArrayList updFileArr = new ArrayList();
    /**
     * 設定request對象。
     *
     * @param request
     *            HttpServletRequest request對象
     */
    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
    /**
     * 設定文件上傳路徑。
     *
     * @param path
     *            用戶指定的文件的上傳路徑。
     */
    public void setUploadPath(String path) {
        this.uploadPath = path;
    }
    /**
     * 文件上傳處理主程序。�������B
     *
     * @return int 操作結果 0 文件操作成功;1 request對象不存在。 2 沒有設定文件保存路徑或者文件保存路徑不正確;3
     *         沒有設定正確的enctype;4 文件操作異常。
     */
    public int process() {
        int status = 0;
        // 文件上傳前,對request對象,上傳路徑以及enctype進行check。
        status = preCheck();
        // 出錯的時候返回錯誤代碼。
        if (status != 0)
            return status;
        try {
            // ��參數或者文件名�u��
            String name = null;
            // 參數的value
            String value = null;
            // 讀取的流是否為文件的標志位
            boolean fileFlag = false;
            // 要存儲的文件。
            File tmpFile = null;
            // 上傳的文件的名字
            String fName = null;
            FileOutputStream baos = null;
            BufferedOutputStream bos = null;
            // ��存儲參數的Hashtable
            paramHt = new Hashtable();
            updFileArr = new ArrayList();
            int rtnPos = 0;
            byte[] buffs = new byte[BUFSIZE * 8];
            // �取得ContentType
            String contentType = request.getContentType();
            int index = contentType.indexOf("boundary=");
            String boundary = "--" + contentType.substring(index + 9);
            String endBoundary = boundary + "--";
            // �從request對象中取得流。
            ServletInputStream sis = request.getInputStream();
            // 讀取1行
            while ((rtnPos = sis.readLine(buffs, 0, buffs.length)) != -1) {
                String strBuff = new String(buffs, 0, rtnPos);
                // 讀取1行數據�n��
                if (strBuff.startsWith(boundary)) {
                    if (name != null && name.trim().length() > 0) {
                        if (fileFlag) {
                            bos.flush();
                            baos.close();
                            bos.close();
                            baos = null;
                            bos = null;
                            updFileArr.add(fName);
                        } else {
                            Object obj = paramHt.get(name);
                            ArrayList al = new ArrayList();
                            if (obj != null) {
                                al = (ArrayList) obj;
                            }
                            al.add(value);
                            System.out.println(value);
                            paramHt.put(name, al);
                        }
                    }
                    name = new String();
                    value = new String();
                    fileFlag = false;
                    fName = new String();
                    rtnPos = sis.readLine(buffs, 0, buffs.length);
                    if (rtnPos != -1) {
                        strBuff = new String(buffs, 0, rtnPos);
                        if (strBuff.toLowerCase().startsWith(
                                "content-disposition: form-data; ")) {
                            int nIndex = strBuff.toLowerCase().indexOf(
                                    "name=\"");
                            int nLastIndex = strBuff.toLowerCase().indexOf(
                                    "\"", nIndex + 6);
                            name = strBuff.substring(nIndex + 6, nLastIndex);
                        }
                        int fIndex = strBuff.toLowerCase().indexOf(
                                "filename=\"");
                        if (fIndex != -1) {
                            fileFlag = true;
                            int fLastIndex = strBuff.toLowerCase().indexOf(
                                    "\"", fIndex + 10);
                            fName = strBuff.substring(fIndex + 10, fLastIndex);
                            fName = getFileName(fName);
                            if (fName == null || fName.trim().length() == 0) {
                                fileFlag = false;
                                sis.readLine(buffs, 0, buffs.length);
                                sis.readLine(buffs, 0, buffs.length);
                                sis.readLine(buffs, 0, buffs.length);
                                continue;
                            }else{
                                fName = getFileNameByTime(fName);
                                sis.readLine(buffs, 0, buffs.length);
                                sis.readLine(buffs, 0, buffs.length);
                            }
                        }
                    }
                } else if (strBuff.startsWith(endBoundary)) {
                    if (name != null && name.trim().length() > 0) {
                        if (fileFlag) {
                            bos.flush();
                            baos.close();
                            bos.close();
                            baos = null;
                            bos = null;
                            updFileArr.add(fName);
                        } else {
                            Object obj = paramHt.get(name);
                            ArrayList al = new ArrayList();
                            if (obj != null) {
                                al = (ArrayList) obj;
                            }
                            al.add(value);
                            paramHt.put(name, al);
                        }
                    }
                } else {
                    if (fileFlag) {
                        if (baos == null && bos == null) {
                            tmpFile = new File(uploadPath + fName);
                            baos = new FileOutputStream(tmpFile);
                            bos = new BufferedOutputStream(baos);
                        }
                        bos.write(buffs, 0, rtnPos);
                        baos.flush();
                    } else {
                        System.out.println("test :" + value + "--" + strBuff);
                        value = value + strBuff;
                    }
                }
            }
        } catch (IOException e) {
            status = 4;
        }
        return status;
    }
    private int preCheck() {
        int errCode = 0;
        if ( request == null )
            return 1;
        if ( uploadPath == null || uploadPath.trim().length() == 0 )
            return 2;
        else{
            File tmpF = new File(uploadPath);
            if (!tmpF.exists())
                return 2;
        }
        String contentType = request.getContentType();
        if ( contentType.indexOf("multipart/form-data") == -1 )
            return 3;
        return errCode;
    }
    public String getParameter(String name){
        String value = "";
        if ( name == null || name.trim().length() == 0 )
            return value;
        value = (paramHt.get(name) == null)?"":(String)((ArrayList)paramHt.get(name)).get(0);
        return value;
    }
    public String[] getParameters(String name){
        if ( name == null || name.trim().length() == 0 )
            return null;
        if ( paramHt.get(name) == null )
            return null;
        ArrayList al = (ArrayList)paramHt.get(name);
        String[] strArr = new String[al.size()];
        for ( int i=0;i<al.size();i++ )
            strArr[i] = (String)al.get(i);
        return strArr;
    }
    
    public int getUpdFileSize(){
        return updFileArr.size();
    }
    
    public String[] getUpdFileNames(){
        String[] strArr = new String[updFileArr.size()];
        for ( int i=0;i<updFileArr.size();i++ )
            strArr[i] = (String)updFileArr.get(i);
        return strArr;
    }
    private String getFileName(String input){
        int fIndex = input.lastIndexOf("\\");
        if (fIndex == -1) {
            fIndex = input.lastIndexOf("/");
            if (fIndex == -1) {
                return input;
            }
        }
        input = input.substring(fIndex + 1);
        return input;
    }
    private String getFileNameByTime(String input){
        int index = input.indexOf(".");
        Date dt = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        return input.substring(0,index) + sdf.format(dt) + input.substring(index);
    }
}

說明

這個類基本解決了上一貼的上一貼說的存在的bug和不足。主要做了如下修正。

  1. 用戶可以設定文件上傳的路徑,這里沒有用request對象的getRealPath方法來取得相對路徑,而是用了絕對路徑。是一個小敗筆。因為有時候用戶只是得到服務器的一個應用,而不知道整個服務器的路徑。但是既然getRealPath自己可以得到,用戶自己取得也可以。
  2. 在文件上傳處理的時候,預先進行了check,把一些可能出現的造成上傳失敗的情況拍查掉。避免該類出現不該出現的異常。
  3. 捕獲了IO異常,避免文件上傳的時候出現異常時程序的不友好表現
  4. 提供了方法返回form表單中其他參數的取得,模擬了HttpServletRequest對象的getParameter和getParameters方法(后面這個方法是叫這個名字么-_-b),取得Parameter的名稱的方法沒有提供,是個小缺陷。
  5. 提供了方法返回上傳的文件的件數和上傳的文件名,方便用戶作其他操作。

現在介紹下JSP頁面中如何用這個類實現上傳。

首先,要把這個類編譯后的class文件拷貝到WEB-INF/classes/目錄下。注意保持package的結構。

在jsp頁面中引用這個類

<%@page import="com.vogoal.util.JspFileUpload"%>

<%
    //初始化
    JspFileUpload jfu = new JspFileUpload();
    //設定request對象
    jfu.setRequest(request);
    //設定上傳的文件路徑
    jfu.setUploadPath("C:\\");
    //上傳處理
    int rtn = jfu.process();
    //取得form中其他input控件參數的值
    String username = jfu.getParameter("username");
    //如果對應同一個參數有多個input控件,返回數組
    String[] usernameArr = jfu.getParameters("username");
    //取得上傳的文件的名字
    String[] fileArr = jfu.getUpdFileNames();
    //取得上傳文件的個數,這個方法有點雞肋
    int fileNumber = jfu.getUpdFileSize();
//下面的是測試輸出的代碼。
//       out.println("parameter:" + username);
//       out.println("parameter size:" + usernameArr.length);
//       out.println("fileArr size:" + fileArr.length);
//       if (fileArr.length > 0)
//              out.println("fileArr 0:" + fileArr[0]);
%>

使用的時候的注意事項

  1. 一定要設定request對象。
  2. 一定要設定正確的上傳路徑。
  3. 執行完了之后才可以得到其他參數,因為執行了之后這些參數才被分析。

1,2兩點如果沒有做到的話,process方法執行的時候匯報錯。

各個用戶可用的方法及說明

設定requet對象。
public void setRequest(HttpServletRequest request)

設定文件上傳的路徑。
public void setUploadPath(String path)

文件上傳處理主程序。
@return int 操作結果 0 文件操作成功;1 request對象不存在。 2 沒有設定文件保存路徑或者文件保存路徑不正確;3
         沒有設定正確的enctype;4 文件操作異常。
public int process()

根據name取得form表單中其他傳遞的參數的值(多個的話返回其中一個)
public String getParameter(String name)

根據name取得form表單中其他傳遞的參數的值(返回數組,可有多個)
public String[] getParameters(String name)

取得上傳成功文件的個數
public int getUpdFileSize()

取得上傳的文件名對應的數組。
public String[] getUpdFileNames()

注意process方法地返回值,在不是0的情況下操作失敗。

以下提供測試類以及測試頁面(見附件):

HelloPostFile.html
HelloPostFile.jsp
寫在jsp中的代碼的測試文件。
HelloPostFileWithClass.html
HelloPostFileWithClass.jsp
抽出class后的測試文件。
src在
WEB-INF/src/
class在
WEB-INF/classes/

另:
由于這個文件被我在中文日文系統下編輯過,注釋出現亂碼,所以大部分都刪掉了,見諒。

下載:WEB-INF.zip



鐵猴 2009-09-22 08:26 發表評論
]]>
java文件上傳http://www.tkk7.com/xlth2006/archive/2009/09/22/295936.html鐵猴鐵猴Tue, 22 Sep 2009 00:08:00 GMThttp://www.tkk7.com/xlth2006/archive/2009/09/22/295936.htmlhttp://www.tkk7.com/xlth2006/comments/295936.htmlhttp://www.tkk7.com/xlth2006/archive/2009/09/22/295936.html#Feedback0http://www.tkk7.com/xlth2006/comments/commentRss/295936.htmlhttp://www.tkk7.com/xlth2006/services/trackbacks/295936.html適用于JSP,將jspSmartUpload.jar置于WEB-INF\lib下

----------------------------------------------------------

Jspsmart1.html

<html>
<head>
    <title>Jspsmart1.html</title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>

<h2>文件上傳范例 - jspSmart</h2>

<form name="Form1" enctype="multipart/form-data" method="post" action="Jspsmart1.jsp">
<p>上傳文件 1:<input type="file" name="File1" size="20" maxlength="20"></p>
<input type="submit" value="上傳">    
<input type="reset" value="清除">  
</form>

</body>
</html>

Jspsmart1.jsp

<%@ page import="com.jspsmart.upload.*" %>
<%@ page contentType="text/html;charset=GB2312" %>

<html>
<head>
    <title>Jspsmart1.jsp</title>
</head>
<body>

<h2>文件上傳范例 - jspSmart</h2>

<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
//計算文件上傳個數
int count=0;         

//SmartUpload的初始化,使用這個jspsmart一定要在一開始就這樣聲明
mySmartUpload.initialize(pageContext);    

//生命限制上傳的文件大小為 5 MB    
mySmartUpload.setMaxFileSize(5 * 1024 * 1024);

//依據form的內容上傳
mySmartUpload.upload();

try {        
    //將文件存放于D:\totalExample\jsp\UploadFile\  
    count = mySmartUpload.save("D:\\totalExample\\jsp\\UploadFile\\");
  
    //打印出上傳文件的個數   
    out.println("您成功上傳"+count + "個文件.");
  
} catch (Exception e) {
    out.println(e.toString());
}
%>
</body>
</html>

---------------------------------------------------------------------

Jspsmart2.html

<html>
<head>
    <title>Jspsmart3.html</title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>

<h2>文件上傳范例 - jspSmart</h2>

<form name="Form1" enctype="multipart/form-data" method="post" action="Jspsmart2.jsp">
<p>上傳文件 1:<input type="file" name="File1" size="20" maxlength="20"></p>
<input type="submit" value="上傳">    
<input type="reset" value="清除">  
</form>

</body>
</html>

Jspsmart2.jsp

<%@ page import="com.jspsmart.upload.*" %>
<%@ page contentType="text/html;charset=GB2312" %>

<html>
<head>
    <title>Jspsmart2.jsp</title>
</head>
<body>

<h2>文件上傳范例 - jspSmart</h2>

<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
//計算文件上傳個數
int count=0;

//SmartUpload的初始化,使用這個jspsmart一定要在一開始就這樣聲明
mySmartUpload.initialize(pageContext);

//依據form的內容上傳
mySmartUpload.upload();

//將上傳的文件一個一個取出來處理
for (int i=0;i<mySmartUpload.getFiles().getCount();i++)
{
       //取出一個文件
       com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
  
       //如果文件存在,則做存檔操作
       if (!myFile.isMissing()) {
  
           //將文件存放于絕對路徑的位置
           myFile.saveAs("D:\\totalExample\\jsp\\UploadFile\\" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL);
   
           //顯示此上傳文件的詳細信息
           out.println("FieldName = " + myFile.getFieldName() + "<BR>");
           out.println("Size = " + myFile.getSize() + "<BR>");
           out.println("FileName = " + myFile.getFileName() + "<BR>");
           out.println("FileExt = " + myFile.getFileExt() + "<BR>");
           out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
           out.println("ContentType = " + myFile.getContentType() + "<BR>");
           out.println("ContentDisp = " + myFile.getContentDisp() +"<BR>");
           out.println("TypeMIME = " + myFile.getTypeMIME() +"<BR>");
           out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>");
           count ++;
       }
}

// 顯示應該上傳的文件數目
out.println("<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>");

// 顯示成功上傳的文件數目
out.println(count + "file(s) uploaded.");
%>

</body>
</html>

------------------------------------------------------------------------------

Jspsmart3.html

<html>
<head>
    <title>Jspsmart3.html</title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>

<h2>文件上傳范例 - jspSmart</h2>

<form name="Form1" enctype="multipart/form-data" method="post" action="Jspsmart2.jsp">
<p>上傳文件 1:<input type="file" name="File1" size="20" maxlength="20"></p>
<input type="submit" value="上傳">    
<input type="reset" value="清除">  
</form>

</body>
</html>

Jspsmart3.jsp

<%@ page import="com.jspsmart.upload.*" %>
<%@ page contentType="text/html;charset=GB2312" %>

<html>
<head>
    <title>Jspsmart3.jsp</title>
</head>
<body>

<h2>文件上傳范例 - jspSmart</h2>

<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%

//計算文件上傳個數
int count=0;         

//SmartUpload之初始化,使用這個jspsmart一定要在一開始就這樣聲明
mySmartUpload.initialize(pageContext);      

//聲明可以上傳的文件類型
mySmartUpload.setAllowedFilesList("htm,html,txt,,");

//限制存檔位置,可存檔于絕對位置
mySmartUpload.setDenyPhysicalPath(false);

//依據 form之內容上傳
mySmartUpload.upload();

//將文件用原本的名字存放于server上的相對路徑
try {
     count = mySmartUpload.save("D:\\totalExample\\jsp\\UploadFile\\", mySmartUpload.SAVE_PHYSICAL);
   
} catch (Exception e)    {

      out.println("<b>Wrong selection : </b>" + e.toString());
    }
     
//打印出總共上傳文件個數
out.println(count + " file(s) uploaded.");
%>

</body>
</html>

---------------------------------------------------------------

download.jsp

<%@ page import="com.jspsmart.upload.*" %>
<%@ page contentType="text/html;charset=GB2312" %>

<html>
<head>
    <title> download.jsp</title>
</head>
<body>

<h2>文件下載范例 - jspSmart</h2>

<jsp:useBean id="mySmartUpload" scope="page"
                                                          class="com.jspsmart.upload.SmartUpload" />

<%
// SmartUpload之初始化
mySmartUpload.initialize(pageContext);

//必須如此聲明,否則將會把文件顯示于瀏覽器中
mySmartUpload.setContentDisposition("inline;");

//將 sample.zip下載,下載默認名稱為downloaded.zip
mySmartUpload.downloadFile("C:\\upload\\sample.zip",
                                                    "application/x-zip-compressed",
                                                    "downloaded.zip");
%>

</body>
</html>



鐵猴 2009-09-22 08:08 發表評論
]]>
主站蜘蛛池模板: 91福利视频免费观看| 亚洲第一精品电影网| 欧美男同gv免费网站观看| 麻豆69堂免费视频| 亚洲日韩在线视频| 亚洲精品自产拍在线观看| 噜噜嘿在线视频免费观看| 日本免费一区二区三区 | 国产白丝无码免费视频| 国产精品亚洲va在线观看| 91亚洲精品第一综合不卡播放| 久久久久亚洲?V成人无码| 免费黄网在线观看| 日韩免费精品视频| 8x成人永久免费视频| av永久免费网站在线观看 | 香蕉视频在线观看免费国产婷婷| 无码中文字幕av免费放dvd| 午夜不卡AV免费| 国产精品自拍亚洲| 亚洲av永久中文无码精品| 国产成人精品亚洲2020| 亚洲毛片无码专区亚洲乱| 亚洲专区先锋影音| 亚洲v高清理论电影| 国产午夜亚洲精品理论片不卡| 免费一区二区三区四区五区| 免费观看的毛片手机视频| 91网站免费观看| 亚洲日韩精品射精日| 91香蕉国产线在线观看免费| 三级黄色片免费看| 国产免费伦精品一区二区三区| 色屁屁在线观看视频免费| 国产成人久久精品亚洲小说| 亚洲AV无码成人精品区日韩| 亚洲色偷偷综合亚洲av78| 亚洲色精品VR一区区三区 | 免费可以看黄的视频s色| 国产va精品免费观看| 国产又黄又爽又猛免费app|