本文整理汇总了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;
}
}
示例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;
}
示例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;
}
}
}
示例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 */
}
示例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";
}
}
示例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;
}
示例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"));
}
示例8: MultipartWrapper
import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
public MultipartWrapper(HttpServletRequest req, String dir)
throws IOException {
super(req);
mreq = new MultipartRequest(req, dir);
}
示例9: setMultipartRequest
import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
* sets a handle to this request object
*/
private void setMultipartRequest(MultipartRequest multipartRequest) {
this.multipartRequest = multipartRequest;
}
示例10: getMultipartRequest
import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
/**
* returns a handle to this request object
*/
private MultipartRequest getMultipartRequest() {
return this.multipartRequest;
}
示例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;
}
示例12: setMultipartRequest
import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
private void setMultipartRequest(MultipartRequest multipartRequest) {
this.multipartRequest = multipartRequest;
}
示例13: getMultipartRequest
import com.oreilly.servlet.MultipartRequest; //导入依赖的package包/类
private MultipartRequest getMultipartRequest() {
return this.multipartRequest;
}
示例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;
}
示例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;
}