社区
Web 开发
帖子详情
请问,JSP如何得到
,输入的文件名称文本字符串呢?
yyhyan
2004-09-22 10:43:06
request.getParameter("FILE1")
不行啊
...全文
1503
8
打赏
收藏
请问,JSP如何得到<input type="FILE" name="FILE1" size="50" />,输入的文件名称文本字符串呢?
request.getParameter("FILE1") 不行啊
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jackcf
2004-09-23
打赏
举报
回复
不要乱说,你们有没有试过,是真的得不到吗,我为什么可以得到呀,呵呵
还说的很好道理一样的,什么二进制呀?!
shaopin
2004-09-23
打赏
举报
回复
如果用JspSmartUpload组件,参照
http://www.ccw.com.cn/htm/app/aprog/01_5_30_2.asp
可以取出文件名
shaopin
2004-09-23
打赏
举报
回复
直接用request.getParameter是取不到的,别不信
方法有2:
1、直接用url方式传递文件名
2、参照 gjd111686(数字金刚)的方法可以取得文件名
gjd111686
2004-09-23
打赏
举报
回复
用JSP分析multipart/form-data基于表单的文件上传
http://blog.csdn.net/gjd111686/archive/2004/08/18/78324.aspx
<%
int iTotalByte,iTotalRead,iReadByte;
iTotalByte=request.getContentLength();
iTotalRead=0;
iReadByte=0;
byte[] Buffer=new byte[iTotalByte];
if(iTotalByte>0)
{
for(;iTotalRead<iTotalByte;iTotalRead+=iReadByte)
{
try
{
iReadByte=request.getInputStream().read(Buffer,iTotalRead,iTotalByte-iTotalRead);
}
catch(Exception e)
{
e.printStackTrace();
}
}
String strContentType=request.getContentType();
//数据处理开始
String strBuffer=new String(Buffer);
%><!--<br>表单数据:<br>strBuffer<br>--><%
String strBoundary="--"+strContentType.substring(strContentType.lastIndexOf("=")+1,strContentType.length());
String strArray[]=strBuffer.split(strBoundary);
String strSubString;
int iBegin,iEnd;
iBegin=0;iEnd=0;
String strFieldName="";
String strFieldValue="";
String strFilePath="";
String strFileName="";
String strFileType="";
boolean bTrue;
bTrue=false;
int iLocation=0;
for(int iIndex=1;iIndex<strArray.length-1;iIndex++)
{
strSubString=strArray[iIndex];
iBegin=strSubString.indexOf("name=\"",0);
if(iBegin!=-1)
{
strFieldName="";strFieldValue="";
strFilePath="";strFileName="";strFileType="";
iEnd=strSubString.indexOf("\"",iBegin+6);
strFieldName=strSubString.substring(iBegin+6,iEnd);
iBegin=strSubString.indexOf("filename=\"",0); if(iBegin!=-1)
{
bTrue=true;
}
iEnd=strSubString.indexOf("\r\n\r\n",0);
if(bTrue==true)
{
//文件路径
strFilePath=strSubString.substring(iBegin+10,strSubString.indexOf("\"",iBegin+10));strFileName=strFilePath.substring(strFilePath.lastIndexOf("\\")+1);
strFileType=strSubString.substring(strSubString.indexOf("Content-Type: ")+14,strSubString.indexOf("\r\n\r\n"));
%><!--<br>文件类型:<br>strFileType<br>--><%
//文件数据
iBegin=strSubString.indexOf("\r\n\r\n",iBegin);
strFieldValue=strSubString.substring(iBegin+4);
strFieldValue=strFieldValue.substring(0,strFieldValue.lastIndexOf("\n")-1);
%><!--<br>文件路径:<br>strFilePath<br>文件名称:<br>strFileName<br>--><%
byte[] pFile=strFieldValue.getBytes();
byte[] pFileExtend=new byte[pFile.length];
iLocation=strBuffer.indexOf("filename=\"",iLocation);
for(int kIndex=iLocation;kIndex<iTotalByte-2;kIndex++)
{
if(Buffer[kIndex]==13&&Buffer[kIndex+2]==13)
{iLocation=kIndex+4;break;}
}
for(int nIndex=0;nIndex<pFile.length;nIndex++)
{
pFileExtend[nIndex]=Buffer[iLocation+nIndex];
}
/*
//保存到Local Disk;
FileOutputStream pFileOutputStream=new FileOutputStream("F:\\Site_App\\UploadFile\\"+strFileName);
pFileOutputStream.write(pFileExtend);
pFileOutputStream.close();
*/
session.putValue(strFieldName+"_FileType",strFileType);
session.putValue(strFieldName+"_FilePath",strFilePath);
session.putValue(strFieldName+"_FileName",strFileName);
session.putValue(strFieldName,pFileExtend);
}
else
{
strFieldValue=strSubString.substring(iEnd+4);
strFieldValue=strFieldValue.substring(0,strFieldValue.lastIndexOf("\n")-1);
session.putValue(strFieldName,strFieldValue);
}
bTrue=false;
}
%><!--<br>表单域名:<br>strFieldName<br>表单域值:<br>strFieldValue<br>--><%
}
//数据处理结束
}
%>
这样(String)session.getValue("表单域名")返回表单域值,而(byte[])session.getValue("File上传控件域名")返回的字节数组就可以用new ByteArrayInputStream(byte[])调用updateBinaryStream来更新到数据库了
xunyiren
2004-09-23
打赏
举报
回复
//通过隐藏域实现
<script language="javascript">
function check(obj)
{
if (obj.upfile.value == "")
{
alert("请选择系统文件!");
return false;
}
document.form1.submit();
}
</script>
<form name="form1" action="upload.jsp" onsubmit="return check(this)">
<!--这里让用户只能选择文件,不能输入\粘贴-->
<input type="file" name="upfile" onKeyPress="return false;" onPaste="return false;" onpropertychange="this.form.filename.value=this.value;alert(this.form.filename.value);">
<input type="hidden" name="filename" value="">
<input type="submit" name="sub" value="确定">
在upload.jsp页面只需:
String filedir=request.getParameter("filename");即可获得客户选择的文件名称
kxx129
2004-09-23
打赏
举报
回复
第一个页面:
<%@ page contentType="text/html;charset=GB2312" %>
<HTML>
<BODY>
<P>选择要上传的文件:<BR>
<FORM action="accept.jsp" method="post" ENCTYPE="multipart/form-data">
<INPUT type=FILE name="boy" size="38">
<BR>
<INPUT type="submit" name ="g" value="提交">
</BODY>
</HTML>
第二个页面:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import ="java.io.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<BODY>
<%try{ //用客户的session的id建立一个临时文件:
String tempFileName=(String)session.getId();
//建立临时文件f1:
File f1=new File("G:/JSP/adou/img/member/",tempFileName);
FileOutputStream o=new FileOutputStream(f1);
//将客户上传的全部信息存入f1:
InputStream in=request.getInputStream();
byte b[]=new byte[10000];
int n;
while( (n=in.read(b))!=-1)
{o.write(b,0,n);
}
o.close();in.close();
//读取临时文件f1,从中获取上传文件的名字,和上传的文件的内容:
RandomAccessFile random=new RandomAccessFile(f1,"r");
//读出f1的第2行,析取出上传文件的名字:
int second=1;
String secondLine=null;
while(second<=2)
{secondLine=random.readLine();
second++;
}
//获取第2行中目录符号'\'最后出现的位置
int position=secondLine.lastIndexOf('\\');
//客户上传的文件的名字是:
String fileName=secondLine.substring(position+1,secondLine.length()-1);
random.seek(0); //再定位到文件f1的开头。
//获取第4行回车符号的位置:
long forthEndPosition=0;
int forth=1;
while((n=random.readByte())!=-1&&(forth<=4))
{ if(n=='\n')
{ forthEndPosition=random.getFilePointer();
forth++;
}
}
//根据客户上传文件的名字,将该文件存入磁盘:
File f2=new File("G:/JSP/adou/img/member/",fileName);
session.setAttribute("Name",fileName);//供showImage.jsp页面使用。
RandomAccessFile random2=new RandomAccessFile(f2,"rw");
//确定出文件f1中包含客户上传的文件的内容的最后位置,即倒数第6行。
random.seek(random.length());
long endPosition=random.getFilePointer();
long mark=endPosition;
int j=1;
while((mark>=0)&&(j<=6))
{ mark--;
random.seek(mark);
n=random.readByte();
if(n=='\n')
{ endPosition=random.getFilePointer();
j++;
}
}
//将random流指向文件f1的第4行结束的位置:
random.seek(forthEndPosition);
long startPoint=random.getFilePointer();
//从f1读出客户上传的文件存入f2(读取从第4行结束位置和倒数第6行之间的内容)。
while(startPoint<endPosition-1)
{ n=random.readByte();
random2.write(n);
startPoint=random.getFilePointer();
}
random2.close();random.close();
f1.delete(); //删除临时文件
}
catch(IOException ee){}
out.print("文件已上传");
%>
</BODY>
</HTML>
guojiafuzhuxi
2004-09-23
打赏
举报
回复
没去想,UP
whirlsun
2004-09-23
打赏
举报
回复
当然,不行了,那是二进制喽,你那样是不能读出来的
JB2-7-HTML
HTML结构(全局属性,实体符号),容器标签(p,div,blockquote,pre,section,article,aside,header,footer),文字标签(br,hr,span,h#,small,sup,sub,a),媒体标签(img,audio,video,figure),列表标签(ol,ul,dl),表格标签(table,tr,td,th,跨行,跨列,colgroup),表单标签(form,
input
,button,select,textarea)等。
GEO关键词优化排名Ai搜索推广软件豆包Deepseek平台系统源码部署贴牌
geo系统源头开发商 支持源码部署 贴牌代理 功能如下: 1.ai自动拓词,大模型抓取行业热词,自动拓词,全方位覆盖 2.自动写高质量文章,系统对接多个大模型接口,想用那个用哪个(可自主溢价) 3.多平台发布,授权账号,多平台多账号发布,喂养ai 4.自动查询收录情况 5.官方媒体投稿,目前对接2万多家媒体,想发哪家发哪家 6.系统两种主题,方便做市场差异化,后台·自己选择 7.其他功能请查看演示 8.新增AI建站,一键创建官网, 9.新增数字人视频克隆 10.新增视频混剪 11.发布官网文章 持续更新中
mac驱动适配win11系统bootcamp-5.1.5640版本
源码直接下载地址: https://pan.quark.cn/s/a4b39357ea24 标题中的“mac驱动兼容win11系统驱动适配版本bootcamp_5.1.5640”明确指出这是一个面向苹果Mac电脑用户的产品,其核心目的是协助用户在Windows 11操作系统上完成驱动程序的安装与配置工作。BootCamp作为苹果公司推出的一项工具,赋予Mac用户在不移除原有macOS系统的前提下,安装并执行Windows操作系统的能力。此特定版本的BootCamp 5.1.5640是专门针对Windows 11环境进行优化的驱动适配版本。 描述部分提及的“mac装win11适配的驱动包”,表明这个压缩文件内含了适配Mac硬件在Windows 11操作系统下运行的驱动程序,涵盖显卡、声卡、网卡等关键设备。用户需首先对文件进行解压缩操作,随后在BootCamp文件夹中找到名为"BootCamp.msi"的安装文件,通过双击执行来启动安装流程。这一步骤是BootCamp驱动安装过程中的核心环节,其中msi文件代表Microsoft Installer格式,其功能在于应用程序的分发与管理。 “BootCamp”标签进一步验证了该压缩包的主要功能,即借助BootCamp服务实现Mac设备与Windows系统之间的硬件兼容性。BootCamp的功能不止于提供驱动程序,还集成了一个引导管理器,允许用户在系统启动时选择运行macOS或Windows。 在压缩包的文件清单中: 1. "AutoUnattend.xml":该文件通常作为无人值守安装的配置文档,旨在自动执行Windows安装过程中的部分或全部设置任务,如用户账户的建立、地区设定的调整、网络配置等,从而提升安装的便捷性。 ...
一个二维计算流体力学(CFD)求解器,用于模拟基于Navier-Stokes方程的不可压缩流体流动。该求解器采用交错网格、有限差分离散化以及分步法来解耦速度场和压力场 附matlab代码.rar
一个二维计算流体力学(CFD)求解器,用于模拟基于Navier-Stokes方程的不可压缩流体流动。该求解器采用交错网格、有限差分离散化以及分步法来解耦速度场和压力场 附matlab代码.rar
Arduino 土壤湿度传感器例程教学
已经博主授权,源码转载自 https://pan.quark.cn/s/031e3cce3229 Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程Arduino 具体编程指南第37部分:关于土壤湿度感应器的实例教程
Web 开发
81,111
社区成员
341,726
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章