• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java MultipartRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.oreilly.servlet.MultipartRequest的典型用法代码示例。如果您正苦于以下问题:Java MultipartRequest类的具体用法?Java MultipartRequest怎么用?Java MultipartRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MultipartRequest类属于com.oreilly.servlet包,在下文中一共展示了MultipartRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: uploadFile

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
 * 上传文件
 * @param multipartRequest
 * @param path 需要上传的文件路径
 * @param exts  允许通过的文件格式 (“.txt|jpg”)
 * @return
 */
public boolean uploadFile(MultipartRequest multipartRequest,String path,String exts){
	try {
		Enumeration files = multipartRequest.getFileNames();       
		// 取得文件详细信息 
		while (files.hasMoreElements()) { 
			   String name =(String)files.nextElement();
		       String fileName = multipartRequest.getFilesystemName(name);
		       if(Ryt.empty(fileName))continue;
		       File currentFile = multipartRequest.getFile(name);
		       	if(!checkExt(exts, fileName)){
		       		currentFile.delete();
		       		return false;
		       	}
		       currentFile.renameTo(new File(path+fileName));
		}
		return true;
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}  
	
}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:30,代码来源:UploadService.java


示例2: getUploadedFile

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
    * Retrieves uploaded Excel file from multipart request and returns
    * as a File object that can be used for parsing and validating data.
    *
    * @param multipartRequest MultipartRequest object containg uploaded
    * file data
    * @return File object representing uploaded file in tmp directory
    * @throws InvalidFormException if no uploaded file can be retrieved
    * from request
    */
   private File getUploadedFile( MultipartRequest multipartRequest ) 
throws InvalidFormException {

// multipart request allows for multiple files, but there
// should never be more than one
Enumeration files = multipartRequest.getFileNames();
           
if ( files == null || !files.hasMoreElements() ) {
    throw new InvalidFormException( "No file uploaded" );
} 

String name = (String) files.nextElement();
File uploadedFile = multipartRequest.getFile( name );
                   
return uploadedFile;
   }
 
开发者ID:tair,项目名称:tairwebapp,代码行数:27,代码来源:MicroarrayLoadHandler.java


示例3: build

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
 * Pseudo-constructor that allows the class to perform any initialization necessary.
 *
 * @param request an HttpServletRequest that has a content-type of multipart.
 * @param tempDir a File representing the temporary directory that can be used to store
 *        file parts as they are uploaded if this is desirable
 * @param maxPostSize the size in bytes beyond which the request should not be read, and a
 *                    FileUploadLimitExceeded exception should be thrown
 * @throws IOException if a problem occurs processing the request of storing temporary
 *                     files
 * @throws FileUploadLimitExceededException if the POST content is longer than the
 *         maxPostSize supplied.
 */
public void build(HttpServletRequest request, final File tempDir, long maxPostSize)
        throws IOException, FileUploadLimitExceededException {

    try {
        // Create a new file in the temp directory in case of file name conflict
        FileRenamePolicy renamePolicy = new FileRenamePolicy() {
            public File rename(File arg0) {
                try {
                    return File.createTempFile("cos", "", tempDir);
                }
                catch (IOException e) {
                    throw new StripesRuntimeException(
                            "Caught an exception while trying to rename an uploaded file", e);
                }
            }
        };

        this.charset = request.getCharacterEncoding();
        this.multipart = new MultipartRequest(request,
                                              tempDir.getAbsolutePath(),
                                              (int) maxPostSize,
                                              this.charset,
                                              renamePolicy);
    }
    catch (IOException ioe) {
        Matcher matcher = EXCEPTION_PATTERN.matcher(ioe.getMessage());

        if (matcher.matches()) {
            throw new FileUploadLimitExceededException(Long.parseLong(matcher.group(2)),
                                                       Long.parseLong(matcher.group(1)));
        }
        else {
            throw ioe;
        }
    }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:50,代码来源:CosMultipartWrapper.java


示例4: doGet

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    MultipartRequest mreq = new MultipartRequest(req, System.getenv("HOME"));
    String name = mreq.getParameter(FIELD_NAME);
    
    PrintWriter writer = resp.getWriter();
    writer.println(name);									/* BAD */
}
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:8,代码来源:Basic40.java


示例5: dispatch

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
public String dispatch(HttpServletRequest request){
	String []specificParams={};
	
	// 需要限制的文件后缀名
	String ext="";
	String path=DEFAULT_UPLOAD_PATH;
	// 设置大小限制(单位:字节)
	final int permitedSize = 80 * 1024 * 1024;
	try {
		// 获取句柄
		MultipartRequest multipartRequest = new MultipartRequest(request, DEFAULT_UPLOAD_PATH,
				permitedSize, "UTF-8", new DefaultFileRenamePolicy());
		
		//封装所有请求参数
		Map<String, String> paramMap=constructionParam(multipartRequest);
		
		String recs=paramMap.get("resource");
		
		if(!Ryt.empty(recs)){
			//上传之前的特殊校验  以及获取指定上传路径和后缀名  最终路径:/usr/data/current/
			specificParams=specificHandle(recs,paramMap);
		
		path=specificParams[0];//路径
		ext=specificParams[1];//后缀名
		//如果返回字符不是文件路径,则直接输出错误信息
		if(path.indexOf("/")<0){
			return path;
			}
		}
		boolean flag=uploadFile(multipartRequest,path,ext);
		if (flag)
			return "success";
		else
			return"fail";
	} catch (IOException e) {
		e.printStackTrace();
		return "expErr";
	} 
}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:40,代码来源:UploadService.java


示例6: constructionParam

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
 * 构建请求参数的map
 * @param multipartRequest
 * @return 所有请求参数map
 */
public Map<String, String>  constructionParam(MultipartRequest multipartRequest){
	Map<String, String> paramMap=new HashMap<String, String>();
	
	// 取得其它非文件字段
	Enumeration params = multipartRequest.getParameterNames();
	
	while (params.hasMoreElements()) {
	    String key = (String)params.nextElement();
	    String value = multipartRequest.getParameter(key);
	    paramMap.put(key, value);
	}                      
	 
	return paramMap;
}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:20,代码来源:UploadService.java


示例7: setDisplayParams

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
 * Retrieves submitted values of parameters that control the showing & hiding
 * of different sections of search form. These parameters will be retrieved
 * from the multipart request and added to Map of search parameters. Display
 * values can then be accessed on JSP using ExpressionSearchFormHelper.
 * 
 * <p>
 * This is necessary since display params will be submitted through the
 * multipart form, and so will not be accessible using the HttpServletRequest
 * on the JSP.
 */
private void setDisplayParams() {
  Map<String, Object> searchParams = getSearchParams();
  MultipartRequest multiRequest = getMultipartRequest();

  searchParams.put("showExpression", multiRequest
      .getParameter("showExpression"));
  searchParams.put("showExperiment", multiRequest
      .getParameter("showExperiment"));
  searchParams.put("showArrayDesign", multiRequest
      .getParameter("showArrayDesign"));
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:23,代码来源:ExpressionSearchHandler.java


示例8: MultipartWrapper

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
public MultipartWrapper(HttpServletRequest req, String dir)
		throws IOException {
	super(req);
	mreq = new MultipartRequest(req, dir);
}
 
开发者ID:shivam091,项目名称:Servlet-Filters,代码行数:6,代码来源:MultipartWrapper.java


示例9: setMultipartRequest

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
 * sets a handle to this request object
 */
private void setMultipartRequest(MultipartRequest multipartRequest) {
  this.multipartRequest = multipartRequest;
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:7,代码来源:ExpressionSearchHandler.java


示例10: getMultipartRequest

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
 * returns a handle to this request object
 */
private MultipartRequest getMultipartRequest() {
  return this.multipartRequest;
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:7,代码来源:ExpressionSearchHandler.java


示例11: process

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
public RequestHandlerResponse process(HttpServletRequest httpRequest,
                                      MultipartRequest multipartRequest)
    throws SQLException, InvalidParameterException, InvalidFormException,
    SessionOutOfTimeException {
  if (httpRequest != null) {
    if (multipartRequest != null) {
      setRequest(httpRequest);
      // holds info like session id which multipart request does not have
      setMultipartRequest(multipartRequest);
      // used for getting and putting parms from the multi-part request
      // action might be in "action" or "search_action" -
      // summary pages use search action
      // because of conflicts with form.action attribute in
      // javascript in Mac IE 4.5
      String action = getMultipartRequest().getParameter("action");
      if (action == null) {
        action = getMultipartRequest().getParameter("search_action");
      }
      type = getMultipartRequest().getParameter("type");
      response = new RequestHandlerResponse();
      setSessionID();
      if (action != null && action.equals("build")) {
        boolean htmlOutput = true;
        if (getMultipartRequest().getParameter("output_type") != null) {
          String outputType =
              getMultipartRequest().getParameter("output_type");
          if (outputType.equalsIgnoreCase("text")) {
            htmlOutput = false;
          }
        }
        build(htmlOutput);
        if (!htmlOutput) {
          response.setAttribute("downloadText", getDownloadText());
          response.setPage("/jsp/common/download_mod.jsp");
        } else {
          response.setPage(listJsp);
        }
      } else {
        throw new InvalidParameterException(
                                            "Invalid search action requested: "
                                                + action
                                                + " for search type: " + type);
      }
    }
  }
  response.setAttribute("input_query_id", getInputQueryID() );
  response.setAttribute("query_id", getQueryID() );
  return response;
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:50,代码来源:KeywordSearchHandler.java


示例12: setMultipartRequest

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
private void setMultipartRequest(MultipartRequest multipartRequest) {
  this.multipartRequest = multipartRequest;
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:4,代码来源:KeywordSearchHandler.java


示例13: getMultipartRequest

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
private MultipartRequest getMultipartRequest() {
  return this.multipartRequest;
}
 
开发者ID:tair,项目名称:tairwebapp,代码行数:4,代码来源:KeywordSearchHandler.java


示例14: process

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
    * Multipart request version of process method. This is needed to handle
    * the uploading of Excel data file through the multipart request. The
    * only action possible through this method is to upload the Excel file.
    * 
    * @param httpRequest HttpServletRequestnull 
    * @param multipartRequest Multipart request object containnull ing submitted
    * params and file handle for uploaded file.
    * @return RequestHandlerResponse containing: URL of JSP to forward to and 
    *  freshly set response attributes 
    * @throws SQLException thrown if a database error occurs while searching
    */ 
   
   public RequestHandlerResponse process( HttpServletRequest httpRequest, 
                                          MultipartRequest multipartRequest )

       throws InvalidFormException, InvalidLoginException, SQLException,
       UnauthorizedRequestException {


checkLogin( httpRequest );

// parse and validate file and redirect user to page for confirming
// data load
RequestHandlerResponse response = confirmFile( httpRequest, 
					       multipartRequest );

       return response;
   }
 
开发者ID:tair,项目名称:tairwebapp,代码行数:30,代码来源:MicroarrayLoadHandler.java


示例15: confirmFile

import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
    * Retrieves updloaded file, parses file and creates response to redirect 
    * curator to page where she can view the results of parsing.
    *
    * @return Response containing LoadableExpressionSet populated with data
    * from file, error logger containing error and warning messages from
    * parsing and row tracker containing objects parsed for each row of
    * data along with URL of JSP to use for displaying results
    * @throws InvalidFormException if an invalid file name is submitted
    * @throws SQLException if a database error occurs while validating
    * file contents
    */
   private RequestHandlerResponse confirmFile( HttpServletRequest request, 
					MultipartRequest multipartRequest ) 
throws InvalidFormException, SQLException {

File file = getUploadedFile( multipartRequest );

// create new expression set to populate with data from file
LoadableExpressionSet expressionSet = new LoadableExpressionSet();

// initialize logging object to track all parsing errors
// and warnings 
ExcelLogger logger = new ExcelLogger();

// initialize row tracker object to record data objects
// in the order submitted in data sheets so results display
// matches input as closely as possible
ExcelRowTracker rowTracker = new ExcelRowTracker();

// parse file and populate expression set w/data
parseFile( file, expressionSet, logger, rowTracker );

// create response to redirect user to confirmation page
RequestHandlerResponse response = new RequestHandlerResponse();
response.setPage( "/jsp/processor/microarray/excel/confirm_excel.jsp" );

// add expression set, logger and row tracker to request for
// use in displaying parsing results
response.setAttribute( "expressionSet", expressionSet );
response.setAttribute( "logger", logger );
response.setAttribute( "rowTracker", rowTracker );

// save objects in session so we can skip parsing when store action
// is selected
HttpSession session = request.getSession();
session.setAttribute( "expressionSet", expressionSet );
session.setAttribute( "logger", logger );
session.setAttribute( "rowTracker", rowTracker );

return response;
   }
 
开发者ID:tair,项目名称:tairwebapp,代码行数:53,代码来源:MicroarrayLoadHandler.java



注:本文中的com.oreilly.servlet.MultipartRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Attribute类代码示例发布时间:2022-05-22
下一篇:
Java TripleMatch类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap