锘??xml version="1.0" encoding="utf-8" standalone="yes"?>午夜精品免费,国产精品永久免费在线,国产婷婷成人久久av免费高清 http://www.aygfsteel.com/csssoft/category/42666.htmlIT楂樿柂涓嶆槸姊?!zh-cnSun, 08 Nov 2009 09:06:53 GMTSun, 08 Nov 2009 09:06:53 GMT60鏂囦歡涓婁紶(FileUpload)http://www.aygfsteel.com/csssoft/archive/2009/11/08/301611.htmlIT榪芥眰鑰?/dc:creator>IT榪芥眰鑰?/author>Sun, 08 Nov 2009 08:30:00 GMThttp://www.aygfsteel.com/csssoft/archive/2009/11/08/301611.htmlhttp://www.aygfsteel.com/csssoft/comments/301611.htmlhttp://www.aygfsteel.com/csssoft/archive/2009/11/08/301611.html#Feedback0http://www.aygfsteel.com/csssoft/comments/commentRss/301611.htmlhttp://www.aygfsteel.com/csssoft/services/trackbacks/301611.html1.浣跨敤JAR
聽聽聽聽聽聽jsp鏂囦歡涓婁紶涓昏浣跨敤浜?jiǎn)涓や釜jar鍖咃紝commons-fileupload-1.2.1.jar鍜宑ommons-io-1.4.jar
2.浠g爜瀹炵幇
聽聽聽聽 public class UploadServlet extends HttpServlet {

聽/**
聽 *
聽 */
聽private static final long serialVersionUID = 1L;

聽private ServletContext sc;

聽private String savePath;

聽@Override
聽protected void doGet(HttpServletRequest request,
聽聽聽HttpServletResponse response) throws ServletException, IOException {
聽聽doPost(request, response);
聽}

聽@Override
聽protected void doPost(HttpServletRequest request,
聽聽聽HttpServletResponse response) throws ServletException, IOException {

聽聽System.out.println("璇鋒眰榪涙潵浜?.........");

聽聽// 璁劇疆璇鋒眰鐨勭紪鐮?br />聽聽request.setCharacterEncoding("UTF-8");

聽聽DiskFileItemFactory factory = new DiskFileItemFactory();//鍒涘緩涓涓鐩樻枃浠跺伐鍘?br />聽聽ServletFileUpload upload = new ServletFileUpload(factory);

聽聽try {
聽聽聽List items = upload.parseRequest(request);
聽聽聽Iterator it = items.iterator();
聽聽聽while (it.hasNext()) {
聽聽聽聽FileItem item = (FileItem) it.next();

聽聽聽聽if (item.isFormField()) {
聽聽聽聽聽System.out.println("琛ㄥ崟鐨勫弬鏁板悕縐幫細(xì)" + item.getFieldName()
聽聽聽聽聽聽聽+ ",瀵瑰簲鐨勫弬鏁板鹼細(xì)" + item.getString("UTF-8"));
聽聽聽聽} else {
聽聽聽聽聽// 鑾峰彇鏂囦歡鎵╁睍鍚?br />聽聽聽聽聽String strtype = item.getName().substring(
聽聽聽聽聽聽聽item.getName().length() - 3,
聽聽聽聽聽聽聽item.getName().length());
聽聽聽聽聽strtype = strtype.toLowerCase();

聽聽聽聽聽if (strtype == "jpg" || strtype == "gif"
聽聽聽聽聽聽聽|| strtype == "txt") {
聽聽聽聽聽聽if (item.getName() != null
聽聽聽聽聽聽聽聽&& !item.getName().equals("")) {
聽聽聽聽聽聽聽System.out.println("涓婁紶鏂囦歡鐨勫ぇ灝忥細(xì)" + item.getSize());
聽聽聽聽聽聽聽System.out.println("涓婁紶鏂囦歡鐨勭被鍨嬶細(xì)"
聽聽聽聽聽聽聽聽聽+ item.getContentType());
聽聽聽聽聽聽聽System.out.println("涓婁紶鏂囦歡鐨勫悕縐幫細(xì)" + item.getName());

聽聽聽聽聽聽聽System.out.println("鏂囦歡鐨勬墿灞曞悕" + strtype);
聽聽聽聽聽聽聽File tempFile = new File(item.getName());
聽聽聽聽聽聽聽File file = new File(
聽聽聽聽聽聽聽聽聽sc.getRealPath("/") + savePath, tempFile
聽聽聽聽聽聽聽聽聽聽聽.getName());
聽聽聽聽聽聽聽item.write(file);

聽聽聽聽聽聽聽request.setAttribute("upload.message", "涓婁紶鏂囦歡鎴愬姛錛?);

聽聽聽聽聽聽} else {
聽聽聽聽聽聽聽request.setAttribute("upload.message",
聽聽聽聽聽聽聽聽聽"娌℃湁閫夋嫨涓婁紶鏂囦歡鑾峰彇鏍煎紡涓嶆敮鎸?);
聽聽聽聽聽聽}
聽聽聽聽聽} else {
聽聽聽聽聽聽request.setAttribute("upload.message", "涓婁紶鏂囦歡鏍煎紡涓嶆敮鎸?);
聽聽聽聽聽}
聽聽聽聽}
聽聽聽}
聽聽} catch (Exception e) {
聽聽聽e.printStackTrace();
聽聽聽request.setAttribute("upload.message", "涓婁紶鏂囦歡涓嶆垚鍔燂紒");
聽聽}
聽聽// 杞彂
聽聽request.getRequestDispatcher("/uploadResult.jsp").forward(request,
聽聽聽聽response);
聽}

聽@Override
聽public void init(ServletConfig config) throws ServletException {

聽聽savePath = config.getInitParameter("savePath");
聽聽sc = config.getServletContext();
聽}



]]>
主站蜘蛛池模板: 华坪县| 茶陵县| 奉化市| 格尔木市| 巩留县| 岑溪市| 大埔区| 连城县| 裕民县| 梅河口市| 许昌县| 广安市| 崇礼县| 岢岚县| 牙克石市| 金寨县| 呼玛县| 准格尔旗| 昌乐县| 平湖市| 绩溪县| 白山市| 和平区| 同心县| 大埔县| 凤阳县| 都昌县| 博乐市| 丘北县| 宣城市| 丁青县| 滨海县| 美姑县| 牙克石市| 屏东县| 永春县| 犍为县| 任丘市| 马鞍山市| 宝丰县| 化州市|