文件上传时,其他文本框的值怎么获得不到?

coffeemilk 2004-01-05 07:48:11
a3.jsp
<HTML><HEAD></head>
<BODY >
<FORM encType="multipart/form-data" method=post name=form1>
<TABLE>
<TR>
<TD><File
<INPUT size=60 type=text name="text"></TD></TR>
<tr>
<td>
<input type="text" name="aaaa" value="aaaaaaaa">
</td>
</tr>
</TABLE>
<input type="button" name="ok" value=" ok " class="button" style="width:76pt" onclick="javascript:gotosubmit('a4.jsp')">
</FORM></BODY></HTML>
<script>
function gotosubmit(submitfile)
{
document.form1.action=submitfile;
document.form1.submit();
}
</script>

a4.jsp也面如下:
<%@ page contentType="text/html;charset=gb2312"%>

<%
String aaa="";
if(request.getParameter("aaaa")!=null)
aaa=new String(request.getParameter("aaaa"));
else
aaa="11111";
out.println(aaa);
%>

如何才可以即能保证文件上传的功能,又能获得其他text框的值?

我在a3.jsp 中把 encType="multipart/form-data"去掉是可以得到文本框的值的,但是我还要得到文件的相关信息,怎么办?
...全文
181 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
bjblz 2004-01-29
  • 打赏
  • 举报
回复
up
Building 2004-01-07
  • 打赏
  • 举报
回复
上面写错了
String fieldvalue = upload.getRequest().getParameterValues(fieldname);
应该是
String[] fieldvalue = upload.getRequest().getParameterValues(fieldname);
返回的是数祖类型的
Building 2004-01-07
  • 打赏
  • 举报
回复
<jsp:useBean id="upload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
upload.initialize(pageContext);
upload.upload();
java.util.Enumeration e = upload.getRequest().getParameterNames();
while(e.hasMoreElements()){
String fieldname = (String)e.nextElement();//取文本框或是其他控件的名称
String fieldvalue = upload.getRequest().getParameterValues(fieldname);//取对应值
}
%>
Fortune2k1 2004-01-07
  • 打赏
  • 举报
回复
in servlet:do post
SmartUpload mySmartUpload = new SmartUpload();
mySmartUpload.initialize(config,request,response);
mySmartUpload.upload();
String fileCategory = (mySmartUpload.getRequest().getParameter("fileCategory")==null)?"":mySmartUpload.getRequest().getParameter("fileCategory").toString() ;

the above code has no problem in my computer when running in weblogic 7.
And chinese character also can be got correctly.
So I think maybe there are some other questions with your code which are not involved with SmartUpload.
coffeemilk 2004-01-06
  • 打赏
  • 举报
回复
to Fortune2k1:
我用在上型机上,

com.jspsmart.upload.SmartUpload up=new com.jspsmart.upload.SmartUpload();
com.jspsmart.upload.Request qs = null;
try
{
up.setMaxFileSize(200*1024*1024); //最大上传文件2M
up.init(config);
up.service(request,response);
up.upload();
qs=up.getRequest();
}
catch(Exception e)
{
String err=Function.ToString(e.getMessage());
if(err.indexOf("Size exceeded for this file")!=-1)
{
out.println("<script>alert('文件太大了,请控制在2M以内!')</script>");
}
}

我也是像你所写的用upload()在先,根本取不到其它文本框的中文值(非中文的是可以取到的)

我要实现的jsp页面就是一个回复文本框 + 可以上传一个附件的功能!
这个问题实在太烦了!
gong1 2004-01-06
  • 打赏
  • 举报
回复
request.getParameter()
^_^
Fortune2k1 2004-01-06
  • 打赏
  • 举报
回复
and chinese character has no problem at all.SmartUpload will resolve it automaticly.
and if you read the source code ,you will know the method upload() is to parth the stream,so no matter what you want to do with SmartUpload, use it first.

Fortune2k1 2004-01-06
  • 打赏
  • 举报
回复
before you write :
txttitle=mySmartUpload.getRequest().getParameter("texttitle").trim();

you must write :
mySmartUpload.upload(); before it first.
coffeemilk 2004-01-06
  • 打赏
  • 举报
回复
to utirei(雨无声) :
根本不可能取到的,因为encType="multipart/form-data形式,它是流的形势,根本不能通过getParameter("texttitle")取到中文值的!
鱼妖 2004-01-06
  • 打赏
  • 举报
回复
就是syuhans(S玉涵S)那么写的啊。
<input type=text name="texttitle">
-->
txttitle=mySmartUpload.getRequest().getParameter("texttitle").trim();
coffeemilk 2004-01-06
  • 打赏
  • 举报
回复
各位大哥,好像不行吧!
chenyongcsdn 2004-01-05
  • 打赏
  • 举报
回复
楼上的方法没有试过,不过有一种更方便的方法:
把你要传的参数放到Url里
比如:a4.jsp?par1='..'&par2='..'
这样就可以取了!
寒冬 2004-01-05
  • 打赏
  • 举报
回复
你是用什么实现上传的,如用jspsmartupload,可以这样
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/>

txttitle=mySmartUpload.getRequest().getParameter("texttitle").trim();
软猫克鲁 2004-01-05
  • 打赏
  • 举报
回复
借花献佛:
:)

String contentType = request.getContentType();
if(contentType != null && contentType.startsWith("multipart/form-data")){
InputStream in = request.getInputStream();
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int data = -1;
int size = 0;
while((data = in.read()) > -1)
{
buf.write(data);
}
//use buf as OutputStream on your server side



}
coffeemilk 2004-01-05
  • 打赏
  • 举报
回复
等,好急,我看以前别人跟我有同样的问题,
但不知他们是如何搞定的?
特再发!

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧