晕,给你写完了,人怎么没了呢……
Ⅱ jsp页面怎么用<input type="file">上传文件到服务器
这个是上传文件的html标签,一般用在表单里面,完整写法是<input type='file' name='file' /> 然后php端用$_POST['file']或者$_GET['file']这样接文件
上传的原理是:上传文件直接上传成功,暂存为.tmp格式的文件,一般是接收之后,将文件移动到别的目录
Ⅲ 用jsp 怎样实现文件上传
你下载一个jspsmart组件,网上很容易下到,用法如下,这是我程序的相关片断,供你参考: <%@ page import="com.jspsmart.upload.*" %>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<% 
 String photoname="photoname";
 
// Variables
 int count=0;        // Initialization
 mySmartUpload.initialize(pageContext); // Upload 
 mySmartUpload.upload();
 
 for (int i=0;i<mySmartUpload.getFiles().getCount();i++){  // Retreive the current file
  com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);  // Save it only if this file exists
  if (!myFile.isMissing()) {
  java.util.Date thedate=new java.util.Date();
     java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); 
     photoname = df.format(thedate);
      photoname +="."+ myFile.getFileExt();
   myFile.saveAs("/docs/docimg/" + photoname);
   count ++;  } }
%>
<% String title="1";
 String author="1";
 String content="1";
 String pdatetime="1";
 String topic="1";
 String imgintro="1";
 String clkcount="1"; if(mySmartUpload.getRequest().getParameter("title")!=null){
 title=(String)mySmartUpload.getRequest().getParameter("title");
 title=new String(title.getBytes("gbk"),"ISO-8859-1");
 }
if(mySmartUpload.getRequest().getParameter("author")!=null){
 author=(String)mySmartUpload.getRequest().getParameter("author");
  author=new String(author.getBytes("gbk"),"ISO-8859-1");
 }
if(mySmartUpload.getRequest().getParameter("content")!=null){
 content=(String)mySmartUpload.getRequest().getParameter("content");
 content=new String(content.getBytes("gbk"),"ISO-8859-1");
 }
if(mySmartUpload.getRequest().getParameter("pdatetime")!=null){
 pdatetime=(String)mySmartUpload.getRequest().getParameter("pdatetime");
 }
if(mySmartUpload.getRequest().getParameter("topic")!=null){
 topic=(String)mySmartUpload.getRequest().getParameter("topic");
 }
 if(mySmartUpload.getRequest().getParameter("imgintro")!=null){
 imgintro=(String)mySmartUpload.getRequest().getParameter("imgintro");
 imgintro=new String(imgintro.getBytes("gbk"),"ISO-8859-1");
 }
if(mySmartUpload.getRequest().getParameter("clkcount")!=null){
 clkcount=(String)mySmartUpload.getRequest().getParameter("clkcount");
 }
//out.println(code+name+birthday);
 %>
Ⅳ jsp如何上传文件
只是jsp部分的话,只要在form标签里加一个“enctype="multipart/form-data"”就好了,读取下载的话只要弄个commons-fileupload之类的插件就很容易解决
这里是下载部分的核心代码:
<%@ page contentType="text/html;charset=gb2312" import="com.jspsmart.upload.*" %>
<%
 String sUrl = (String)request.getAttribute("fileurl");
 SmartUpload su = new SmartUpload();
 su.initialize(pageContext);
 //设定contentDisposition为null以禁止浏览器自动打开文件,保证点击链接后是下载文件。若不设定,则下载的文件扩展名为doc时,浏览器将自动用word打开它;扩展名为pdf时,浏览器将用acrobat打开。
 su.setContentDisposition(null);
 su.downloadFile(sUrl);
%>
但是归根结底,你还是要一个存放文件路径的数据库啊,否则你下载时候下载地址每次都写死或者手动输入??如果要动态读取的话还是要建一个存放文件路径的数据库的
Ⅳ JSP上传文本文件,并在页面显示其内容
就是提交完成后,再把*.txt文件中包含的内容显示出来?
这个必须要调用java类中的方法啊 
否则无法读取文件内容的
Ⅵ 怎么在 jsp 页面中上传文件
使用jsp smartupload
示例:部分文件代码  具体实现 找些教材
 
UploadServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.*;
import java.text.*;
import java.util.*;
/*******************************************************/
/*    该实例中尽可能多地用到了一些方法,在实际应用中            */
/*     我们可以根据自己的需要进行取舍!                         */
/*******************************************************/
public class UploadServlet extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 新建一个SmartUpload对象,此项是必须的
		SmartUpload myupload = new SmartUpload();		
		// 初始化,此项是必须的
		ServletConfig config = getServletConfig();
		myupload.initialize(config,request,response);		
		response.setContentType("text/html");
		response.setCharacterEncoding("gb2312");
		PrintWriter out = response.getWriter();
		out.println("<h2>处理上传的文件</h2>");
		out.println("<hr>");
		
		try{			
			// 限制每个上传文件的最大长度
			myupload.setMaxFileSize(1024*1024);		
			// 限制总上传数据的长度
			myupload.setTotalMaxFileSize(5*1024*1024);		
			// 设定允许上传的文件(通过扩展名限制)
			 myupload.setAllowedFilesList("doc,txt,jpg,gif");	
			// 设定禁止上传的文件(通过扩展名限制)
			 myupload.setDeniedFilesList("exe,bat,jsp,htm,html,,");			
			// 上传文件,此项是必须的
			myupload.upload();			
			// 统计上传文件的总数
			int count = myupload.getFiles().getCount();			
			// 取得Request对象
			Request myRequest = myupload.getRequest();		
			String rndFilename,fileExtName,fileName,filePathName,memo;
			Date dt = null; 
			SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS"); 			
			
			// 逐一提取上传文件信息,同时可保存文件	
			for (int i=0;i<count;i++)
			{
				//取得一个上传文件
				File file = myupload.getFiles().getFile(i);				
				// 若文件不存在则继续
				if (file.isMissing()) continue;		
				// 取得文件名
				fileName = file.getFileName();
				// 取得文件全名
				filePathName = file.getFilePathName();
				// 取得文件扩展名
				fileExtName = file.getFileExt();
				// 取得随机文件名
				dt = new Date(System.currentTimeMillis()); 
				Thread.sleep(100);
				rndFilename= fmt.format(dt)+"."+fileExtName;			
				memo = myRequest.getParameter("memo"+i);
	
				// 显示当前文件信息
				out.println("第"+(i+1)+"个文件的文件信息:<br>");
				out.println(" 文件名为:"+fileName+"<br>");
				out.println(" 文件扩展名为:"+fileExtName+"<br>");
				out.println(" 文件全名为:"+filePathName+"<br>");
				out.println(" 文件大小为:"+file.getSize()+"字节<br>");
				out.println(" 文件备注为:"+memo+"<br>");
				out.println(" 文件随机文件名为:"+rndFilename+"<br><br>");
		
				// 将文件另存,以WEB应用的根目录作为上传文件的根目录
				file.saveAs("/upload/" + rndFilename,myupload.SAVE_VIRTUAL);
			}
			out.println(count+"个文件上传成功!<br>");			
		}catch(Exception ex){
			out.println("上传文件超过了限制条件,上传失败!<br>");
			out.println("错误原因:<br>"+ex.toString());
		}
		out.flush();
		out.close();
	}
}
Ⅶ jsp 如何实现文件上传和下载功能
上传:
MyjspForm mf = (MyjspForm) form;// TODO Auto-generated method stub
FormFile fname=mf.getFname();
byte [] fn = fname.getFileData();
OutputStream out = new FileOutputStream("D:\"+fname.getFileName());
Date date = new Date();
String title = fname.getFileName();
String url = "d:\"+fname.getFileName();
Upload ul = new Upload();
ul.setDate(date);
ul.setTitle(title);
ul.setUrl(url);
UploadDAO uld = new UploadDAO();
uld.save(ul);
out.write(fn);
out.close();
下载:
DownloadForm downloadForm = (DownloadForm)form;
String fname = request.getParameter("furl");
FileInputStream fi = new FileInputStream(fname);
byte[] bt = new byte[fi.available()];
fi.read(bt);
//设置文件是下载斗喊还是打开以及打开的方式msdownload表示下载粗弯;设置字湖集,//主要是解决文件中的中文信息
response.setContentType("application/msdownload;charset=gbk");
//文件下载后的默认保存名及打开方式
String contentDisposition = "attachment; filename=" + "java.txt";
response.setHeader("Content-Disposition",contentDisposition);
//设岩销闷置下载长度
response.setContentLength(bt.length);
ServletOutputStream sos = response.getOutputStream();
sos.write(bt);
return null;
Ⅷ 怎样用JspSmartUpload实现文件上传攻略
2、增加属性:ENCTYPE="multipart/form-data" 下面是一个用于上传文件的FORM表单的例子: <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="/jspSmartUpload/upload.jsp"> <INPUT TYPE="FILE" NAME="MYFILE"> <INPUT TYPE="SUBMIT"> </FORM>二 上传的例子 1、上传页面upload.html 本页面提供表单,让用户选择要上传的文件,点击"上传"按钮执行上传操作。 页面源码如下: <!-- 文件名:upload.html 作 者:纵横软件制作中心雨亦奇([email protected]) --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>文件上传</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <p></p> <p align="center">上传文件选择</p> <FORM METHOD="POST" ACTION="jsp/do_upload.jsp" ENCTYPE="multipart/form-data"> <input type="hidden" name="TEST" value="good"> <table width="75%" border="1" align="center"> <tr> <td><div align="center">1、 <input type="FILE" name="FILE1" size="30"> </div></td> </tr> <tr> <td><div align="center">2、 <input type="FILE" name="FILE2" size="30"> </div></td> </tr> <tr> <td><div align="center">3、 <input type="FILE" name="FILE3" size="30"> </div></td> </tr> <tr> <td><div align="center">4、 <input type="FILE" name="FILE4" size="30"> </div></td> </tr> <tr> <td><div align="center"> <input type="submit" name="Submit" value="上传它!"> </div></td> </tr> </table> </FORM> </body> </html>2、上传处理页面do_upload.jsp 本页面执行文件上传操作。页面源码中详细介绍了上传方法的用法,在此不赘述了。 for (int i=0;i<su.getFiles().getCount();i++) { com.jspsmart.upload.File file = su.getFiles().getFile(i); // 若文件不存在则继续 if (file.isMissing()) continue; // 显示当前文件信息 out.println("<TABLE BORDER=1>"); out.println("<TR><TD>表单项名(FieldName)</TD><TD>" + file.getFieldName() + "</TD></TR>"); out.println("<TR><TD>文件长度(Size)</TD><TD>" + file.getSize() + "</TD></TR>"); out.println("<TR><TD>文件名(FileName)</TD><TD>" + file.getFileName() + "</TD></TR>"); out.println("<TR><TD>文件扩展名(FileExt)</TD><TD>" + file.getFileExt() + "</TD></TR>"); out.println("<TR><TD>文件全名(FilePathName)</TD><TD>" + file.getFilePathName() + "</TD></TR>"); out.println("</TABLE><BR>"); // 将文件另存 // file.saveAs("/upload/" + myFile.getFileName()); // 另存到以WEB应用程序的根目录为文件根目录的目录下 // file.saveAs("/upload/" + myFile.getFileName(), su.SAVE_VIRTUAL); // 另存到操作系统的根目录为文件根目录的目录下 // file.saveAs("c:\\temp\\" + myFile.getFileName(), su.SAVE_PHYSICAL); } %> </body> </html>(T007)