資源文件命名格式: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默認語言為中文:
從sun的官網http://java.sun.com/javase/downloads/?intcmp=1281下載JDK,當前最新版本是jdk-6u10-windows-i586-p.exe,這個是正式版的。
同時在sun的網站http://java.sun.com/products/sjwtoolkit/zh_download-2_5_2.html下載WTK,當前最新版本是sun_java_wireless_toolkit-2_5_2-ml-windows.exe。
先安裝JDK再安裝WTK,我的安裝路徑是:D:"Java"jdk1.6.0_10和D:"Java"WTK2.5.2
從eclipse的官網 http://www.eclipse.org/downloads/下載eclipse,我用的是:eclipse-java-ganymede-SR1-win32.zip,解壓到:XX:"eclipse
從eclipseme的官網 http://sourceforge.net/project/showfiles.php?group_id=86829下載eclipseme.當前最新版本是eclipseeclipseme.feature_1.7.9_site.zip
到 “首選項”找到,Java—>調試,將“發生未不捕獲到的異常時暫掛執行”與“在發生編譯錯誤時暫掛執行”這兩個選項調為“未選中”狀態,再把下面的調試器超時(毫秒)的右側數值設置為15000
運行eclipse,配置自己學習的工作路徑,選擇 幫助—>軟件更新—>查找并安裝—>搜索要安裝的新功能部件,選擇 新建已歸檔的站點,選擇eclipseme.feature_1.7.9_site.zip文件,安裝,重啟eclipse
選擇 首選項—>J2ME—>Device Management—>Import 在Specify search directory下,選擇你所裝的WTK模擬器的目錄;選擇 Refresh ,后按完成,使用DefaultColorPhone為默認模式,這時已為eclipse配置上了模擬器
需要使用插件ProGuard,從ProGuard的官網下載ProGuard,當前的最新版本是:proguard4.3beta2.tar.gz,解壓到:XX:"proguard4.3
到 Eclipse的“首選項”找到,J2ME—>Packaging—>obfuscation,在Proguard Root Directory右邊的框中,選擇剛才解壓的proguard4.3的文件夾(XX:"proguard4.3),點擊應用,這時為eclipse配置上了混淆器
· 使用eclipse進行J2ME開發
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;
}
}
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");
}
}
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");
文件下載:
-----------------------------------------
文件的超連接寫法范例:
<% 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();
}
%>
這個問題的確很煩人,其實都是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 自動提示 卡 慢 的問題。
特點:
先貼上傳類,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和不足。主要做了如下修正。
現在介紹下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,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/
另:
由于這個文件被我在中文日文系統下編輯過,注釋出現亂碼,所以大部分都刪掉了,見諒。
----------------------------------------------------------
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>