[JSP ] 使用jspSmartUpload的一些問題
大家好~
最近寫了一個檔案上傳的JSP程式,作業環境是WIN XP,伺服器:tomcat4.1.3,使用的上
傳元件是:jspSmartUpload
一開始寫了一個檔案上傳的網頁,剛開始測試都成功,檔案也成功上傳,但是想說在上傳
的表單中加入一些text的欄位,但發現接收端卻接收不到text所傳來的資料,我的程式碼
如下
upload.html(一開始的畫面)
---------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>無標題文件</title>
</head>
<body>
<h1>檔案上傳</h1><hr />
<form action="getFile.jsp" method="post" enctype="multipart/form-data"
name="FileName">
請選擇欲上傳的檔案...<br>
上傳檔案1:<input type="file" name="file1" size="40" /><br />
上傳檔案2:<input type="file" name="file2" size="40" /><br />
TEST:<input type="text" name="id" /><br />
--------想說在這邊加入一個text傳送看看,沒有想到出問題...----------
<input type="submit" name="submit" />
<input type="reset" name="reset" />
</form>
</body>
</html>
----------------------------------------------
getFile.jsp(負責處理檔案上傳的接收檔)
--------------------------------------------------
<%@ page contentType="text/html; charset=big5" language="java"
import="java.sql.*" errorPage="" %>
<%@ page import="com.jspsmart.upload.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<%
//設定使用BIG5碼
request.setCharacterEncoding("Big5");
response.setContentType("text/html; charset=Big5");
%>
<title>無標題文件</title>
</head>
<body>
<jsp:useBean id="myUpload" scope="page"
class="com.jspsmart.upload.SmartUpload">
</jsp:useBean>
request the file...
<%
String savePath = "/upload";
int maxPostSize = 10 * 1024 * 1024;
int fcount = 0;
myUpload.initialize(pageContext);
myUpload.setTotalMaxFileSize(maxPostSize);
String ans = myUpload.getRequest().getParameter("id");//這行接收開始畫面的
text欄位所傳來的?
out.println(ans);//將接收的?列印出來
myUpload.upload();
try {
fcount = myUpload.save(savePath);
out.println(fcount);
}catch (Exception ex) {
out.println("error");
}
%>
</body>
</html>
我試了很久,也有去參考別人的寫法,主要是因為enctype="multipart/form-data",所以
接收文字會有問題,我已經有改過,但是不知道為什麼ans變數都接收不到
傳來的id,所以列印出來都是null,可以請大家幫我看一下,問題出在哪邊嗎@@?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.228.126.143