使用smartupload这个组件来上传吧。使用方法可以搜索一下,很多教程。
解决方案 »
- jsp 提交到 servlet 问题
- 客户端是用C/C++或其他语言编写的程序能调用服务端是用CXF发布的web service吗?
- jsp 页面读入文件判断用户名 是否存在 和密码是否正确
- eclipse怎么去掉JSP等的检查
- 求jsp聊天室,100分送上
- Myfaces 构建复杂table 问题
- 关于多人同时访问的问题
- 求去除页面中javascrit代码的正则表达式
- 关于有框架的jsp页面中的post请求问题,烦各位大侠帮一把
- javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to t
- cookie 的问题
- 一个JSP做的留言本的问题
<head>
<title>文件上传示例</title>
</head><body>
<center>文件上传示例</center>
<hr>
<form name=form1 enctype=multipart/form-data method=post action="upload.jsp">
<p>上传文件1<input type=file name=File1 size=20 ></p>
<p>文件意描述:<input type=text name=File1 size=20 ></p>
<p>上传文件2:<input type=file name=File2 size=20 ></p>
<p>文件2描述:<input type=text name=File2 size=20 ></p>
<p>上传文件3;<input type=file name=File3 size=20 ></p>
<p>文件3描述:<input type=text name=File3 size=20 ></p>
<p>
<input type=submit value="上传" >
<input type=reset value="清楚">
</p>
</form>
</body>
</html><%@ page contentType="text/html;charset=GB2312"
import="com.jspsmart.upload.*"
%><jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><html>
<head>
<title>文件上传</title>
</head><body>
<center>文件上传</center>
<hr>
<%
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
//逐个处理上传文件
int count=0;
for(int i=0;i<mySmartUpload.getFiles().getCount();i++)
{
//取出当前文件
File myFile=mySmartUpload.getFiles().getFile(i);
//如果文件存在,则保存
if(!myFile.isMissing())
{
//用相对路径保存
myFile.saveAs("upload/"+myFile.getFileName(),mySmartUpload.SAVE_VIRTUAL);
//用绝对路径保存
//myFile.saveAs("c:\\"+myFile.getFileName(),mySmartUpload.SAVE_PHYSICAL);
out.println("FieldName="+myFile.getFieldName()+"<br>");
out.println("Size="+myFile.getSize()+"<br>");
out.println("FileName="+myFile.getFileName()+",");
out.println("FileExt="+myFile.getFileExt()+",");
out.println("FilePathNmae="+myFile.getFilePathName()+"<br>");
out.println("ContextType="+myFile.getContentType()+",");
out.println("ContentDisp="+myFile.getContentDisp()+"<br>");
out.println("TypeMIME="+myFile.getTypeMIME()+",");
out.println("SubTypeMIME="+myFile.getSubTypeMIME()+"<br>");
out.println("<hr>");
count++;
}
}
out.println("用getParameter方法获取<br>");
out.println("File1="+mySmartUpload.getRequest().getParameter("File1")+"<br>");
out.println("File2="+mySmartUpload.getRequest().getParameter("File2")+"<br>");
out.println("File3="+mySmartUpload.getRequest().getParameter("File3")+"<br>");
out.println("<hr>");
out.println("用遍历得方法获取<br>");
java.util.Enumeration e=mySmartUpload.getRequest().getParameterNames();
while(e.hasMoreElements())
{
String key=(String)e.nextElement();
String[] values=mySmartUpload.getRequest().getParameterValues(key);
//取出当前参数值
for(int i=0;i<values.length;i++)
out.println(key+"="+values[i]+"<br>");
}
%>
</body>
</html>