亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1384 | 回復(fù): 0
打印 上一主題 下一主題

上傳文件同時獲取提交的參數(shù)實現(xiàn)方法 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2007-11-30 18:07 |只看該作者 |倒序瀏覽

"text/html; charset=gb2312"%>
"java.util.*"%>
"java.sql.*"%>
"java.io.*"%>
"org.apache.commons.fileupload.*" %>
"java.text.*" %>
"javax.servlet.*,javax.servlet.http.*"%>
"conn" scope="page" class="DBLink.DBSQL"/>
"ReadTemplates" scope="page" class="ball.news.ReadTemplates"/>
"WriteHtml" scope="page" class="ball.news.WriteHtml"/>
"ReplaceAll" scope="page" class="ball.news.ReplaceAll"/>
//request.setCharacterEncoding("gb2312");

try{
String dir=request.getRealPath(".");
DiskFileUpload fu = new DiskFileUpload();

fu.setSizeMax(4194304); //設(shè)置文件大小. 這里文件只能上傳4M以內(nèi)的

fu.setSizeThreshold(4096); //設(shè)置緩沖大小.

fu.setRepositoryPath(dir+"/ball/news/images"); //設(shè)置臨時目錄.   List fileItems = fu.parseRequest(request); //解析請求,返回一個集合.

Iterator i = fileItems.iterator();
String fieldvalue="";
String ff = "";
String picname="false";
Object tt = "";
Vector v = new Vector();

while(i.hasNext())
{

FileItem fi = (FileItem)i.next();

if(fi.isFormField()) //這是用來確定是否為文件屬性,
{

String fieldName = fi.getFieldName(); //這里取得表單名
fieldvalue=fi.getString(); //這里取得表單值

v.addElement(fieldvalue);

}

else //這里開始外理文件
{

File fullFile = new File(fi.getName());
ff = fullFile.getName();
String rr = "";

java.util.Date date2 = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMddHHmmss"); //取得時間
String str2 = formatter.format(date2);
StringTokenizer st = new StringTokenizer(ff,".");
if (st.hasMoreTokens()){
String test12 = st.nextToken();
rr = st.nextToken();
//System.out.println(rr);
}
if (rr.equals("")&&!rr.equals("gif")&&!rr.equals("jpg")&&!rr.equals("jpeg"))
{
picname = "false";
}

else
{
picname = str2+"."+rr; //以時間為圖片名稱

File savedFile = new File(getServletContext().getRealPath("/ball/news/images/"),picname);

fi.write(savedFile); //上傳到服務(wù)器
}
//System.out.println("picname------------------------"+picname);
}
//System.out.println("v------------------------"+v);
}
String[] flag = {"","","","","",""};

//將數(shù)據(jù)寫入到數(shù)據(jù)庫
Object newtype1 = v.elementAt(0);
String t = newtype1.toString();
int
newtype = Integer.parseInt(t);
Object rowid1 = v.elementAt(1);
String rowid = rowid1.toString();
Object title1 = v.elementAt(2);
String title = title1.toString();
Object content1 = v.elementAt(3);
String content = content1.toString();
// System.out.println(down);
java.util.Date date = new java.util.Date();
String strdate = date.toLocaleString();

java.util.Date StrDate1 = new java.util.Date();
String StrDate = StrDate1.toLocaleString(); // 新聞發(fā)布時間
//String newtype="0";
conn.openDB();
String sql = "select top 5 * from b_news where newtype="+newtype+" order by id desc";
String strTemp="相關(guān)新聞";
ResultSet rs = conn.executeQuery(sql);
while (rs.next())
{
String t2 = rs.getString(2);
String t4 = rs.getString(4);
strTemp += "";
strTemp +="+t4+">";
strTemp += t2;
strTemp +="";
}
strTemp +="";
rs.close();

//讀取模板

String filePath = "";
filePath = request.getRealPath("\\ball\\news\\pnews.template");
String templateContent = null;
try{
templateContent = ReadTemplates.getTlpContent(filePath);
System.out.println(templateContent);
}
catch(Exception e)
{
System.out.println("error to template!");
}
//替換模板中的內(nèi)容
//System.out.println("picname--------------------------------"+picname);

templateContent = ReplaceAll.replace(templateContent,flag[0],title);
templateContent = ReplaceAll.replace(templateContent,flag[1],StrDate);
//templateContent = ReplaceAll.replace(templateContent,flag[2],editer);
templateContent = ReplaceAll.replace(templateContent,flag[3],content);
templateContent = ReplaceAll.replace(templateContent,flag[4],strTemp);
templateContent = ReplaceAll.replace(templateContent,flag[5],picname);

// 根據(jù)時間得文件名與路徑名

Calendar calendar = Calendar.getInstance();
String fileName = String.valueOf(calendar.getTimeInMillis()) +".html";
String pathName = request.getRealPath("ball/news")+"\\"+ calendar.get(Calendar.YEAR) + "\\"+ (calendar.get(Calendar.MONTH)+1) +"\\"+ calendar.get(Calendar.DAY_OF_MONTH)+"\\";
String url = calendar.get(Calendar.YEAR) + "/"+ (calendar.get(Calendar.MONTH)+1) +"/"+ calendar.get(Calendar.DAY_OF_MONTH)+"/";
url +=fileName;
//System.out.println(url);

try{
WriteHtml.save(templateContent,pathName,fileName);
}catch(Exception e){
System.out.println("error to html!-----------"+e.getMessage());
}

//寫入數(shù)據(jù)庫
String sqlInsert = null;
if (!picname.equals("false")){
sqlInsert = "insert into b_news (title,content,url,picture,newtype,addtime,rowid) values ('"+title+"','"+content+"','"+url+"','"+picname+"','"+newtype+"',getdate(),'"+rowid+"')";
}
else
{
picname="images/"+picname;
sqlInsert = "insert into b_news (title,content,url,newtype,addtime,rowid) values ('"+title+"','"+content+"','"+url+"','"+newtype+"',getdate(),'"+rowid+"')";
}
//System.out.println("sql insert---------------"+sqlInsert);
conn.executeUpdate (sqlInsert);
}
catch(Exception e)
{
System.out.println("upload error------------------"+e.getMessage());
}

%>
"新聞生成html成功了!");%>

作者: 不詳
來源:ziying 的 Blog  


本文來自ChinaUnix博客,如果查看原文請點:http://blog.chinaunix.net/u/18156/showart_433578.html
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP