您的位置:首页 > 编程语言 > Java开发

MyEclipse------如何添加jspsmartupload.jar+文件上传到服务器

2016-03-24 17:31 591 查看
下载地址:http://download.csdn.net/detail/heidan2006/182263

如何添加jspsmartupload.jar:
右键“Web”工程-》properties-》Libraries-》Add External JARs...-》找到“jspsmartupload.jar”,添加进去
-》点击“OK”-》找到“E:\MyEclipse2014\projects\Web\WebRoot\WEB-INF\lib”路径,把“jspsmartupload.jar”添加进去
-》重启tomcat,不然出现invalid

uploadForm.html

<!DOCTYPE html>
<html>
<head>
<title>uploadForm.html</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=gbk">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>

<body>
<form action="usingsmartupload.jsp" method="post" enctype="multipart/form-data" name="theFile">
<input type="file" name="file" size="30"/><br>
<input type="submit" value="上传" name="btn">
</form>
</body>
</html>


usingsmartupload.jsp

<%@page import="java.io.File"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- java.sql.*包可以不导 -->
<%@page import="java.sql.*" %>
<%@page import="com.jspsmart.upload.*" %>
<%@page import="java.io.*" %>
<jsp:useBean id="the" scope="page" class="com.jspsmart.upload.SmartUpload"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'usingsmartupload.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">

<!-- 这段代码可以不加 -->
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">

<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
try{
the.initialize(pageContext);
the.setTotalMaxFileSize(5*1024*1024);
the.upload();
String fn=the.getFiles().getFile(0).getFieldName();

path=request.getRealPath("")+"\\myfile";
//java.io.File d=new java.io.File(path);
File d=new File(path);
if(!d.exists()){
d.mkdirs();
}

the.save(path);
//the.save("E:\\FFOutput\\");
out.print(fn);
out.print("文件已上传成功!!!");
}
catch(Exception e){
e.printStackTrace();
}
%>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: