作者squallindex (squallindex)
看板java
标题[JSP ] 使用jspSmartUpload的一些问题
时间Tue Jul 11 15:39:07 2006
大家好~
最近写了一个档案上传的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