⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 upload1action.java

📁 轻松实现上传功能 struts,
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.upload.struts.action;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.upload.struts.form.Upload1Form;

/** 
 * MyEclipse Struts
 * Creation date: 10-27-2007
 * 
 * XDoclet definition:
 * @struts.action path="/upload1" name="upload1Form" input="/form/upload1.jsp" parameter="method" scope="request" validate="true"
 */
public class Upload1Action extends DispatchAction {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward no1(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Upload1Form upload1Form = (Upload1Form) form;// TODO Auto-generated method stub
		
		
		return null;
	}

	public ActionForward no2(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Upload1Form upload1Form = (Upload1Form) form;// TODO Auto-generated method stub
//		try {
//			String fileName=f.getFilename();
//			String filepath=f.getFilepath();
//		    String filePath=request.getRealPath("/");
//		    
////            response.setContentType(this.getContentType(fileName));
//            response.setHeader("Content-disposition", "attachment;filename="
//                    + URLEncoder.encode(fileName, "utf-8"));
//            InputStream fis = new FileInputStream(filePath + fileName);
//            BufferedInputStream bis = new BufferedInputStream(fis);
//            OutputStream fos = response.getOutputStream();
//            BufferedOutputStream bos = new BufferedOutputStream(fos);
//            int bytesRead = 0;
//            byte[] buffer = new byte[5 * 1024];
//            while ((bytesRead = bis.read(buffer)) != -1) {
//                bos.write(buffer, 0, bytesRead);//将文件发送到客户端
//            }
//        }
//        catch (IOException e) {
//        }
//		
		return null;
	}
	public ActionForward no3(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Upload1Form upload1Form = (Upload1Form) form;// TODO Auto-generated method stub
		   HttpSession session=request.getSession();
		   response.setContentType("text/html;charset=utf-8");
		
		 
		   String filepath = request.getRealPath("/lin/");
		   System.out.print(filepath);
		   File dir=new File(filepath);
		   File file[]=dir.listFiles();
		   
			   try {
				   
					PrintWriter out = response.getWriter();
					for(int i=0;i<=file.length;i++)
					{if(file[i]!=null)
						System.out.print("fdafafea");
						out.print("<br>"+"<a href="+file[i]+">"+"no"+i+"</a>");
					 }
					
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}   
//		   file[i]
		  
		return null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -