Posted on 2007-04-12 11:03
sxt 阅读(410)
评论(0) 编辑 收藏 所属分类:
JSP
index.jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%> <% //String path = request.getContextPath(); //String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>
<head> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="/blog/styles.css"> --> </head> <body> 文件上传范例-jspsmart <form name="form1" method="post" action="Jspsmart.jsp" enctype="multipart/form-data"> <p> 上传文件1:<INPUT type="file" name="File1" size="20"></p> <INPUT type="submit" value="上传"> <INPUT type="reset" value="清除"> </form> </body> </html>
|
Jspsmart.jsp代码:
<%@ page language="java" import="com.jspsmart.upload.*" pageEncoding="GB2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>
<head> <title>My JSP 'Jspsmart.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page">
</head> <body> <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/> <% int count=0; mySmartUpload.initialize(pageContext); mySmartUpload.setMaxFileSize(5*1024*1024); mySmartUpload.upload(); out.print("mySmartUpload.upload()<br>"); try{ // mySmartUpload.getFiles().getFile(0).saveAs("D:\\aaa\\1212.rar",mySmartUpload.SAVE_PHYSICAL); count = mySmartUpload.save("file\\"); out.print("count = mySmartUpload.save(d:\\aaa\\);<br>"); } catch(Exception e){ out.println(e.toString()); } %> skdfjskfjksdjfj <br> </body> </html>
|
其中加粗的红色字体是必须要有的。