0
我想在我的程序中獲取下拉值,以便將字符串合併到我的文件路徑,以便根據用戶輸入動態地改變路徑.iam新到apache commoms,在我之前正在使用o'reilly api。在servlet中使用apache commons獲取下拉值
這裏是我的代碼:
@Override
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, java.io.IOException
{
//FileItem f1;
String d1= request.getParameter("sel1");
String d2=request.getParameter("sel2");
String d3="/home/adapco/Desktop/output";
String conc=d3+"/"+d1+"/"+d2+"/";
filePath=(new StringBuilder()).append(conc).toString();
// filePath="/home/adapco/Desktop/output/";
isMultipart = ServletFileUpload.isMultipartContent(request);
}
我試圖調試和我收到的賴特文件路徑,但同時進一步出發,fileItems顯示大小= 0,並且不進入,因爲size0的環。
filePath="/home/adapco/Desktop/output/";
如果我將上傳路徑傳遞給filePath,它工作正常。
List fileItems = upload.parseRequest(request);
Iterator i = fileItems.iterator();
while (i.hasNext())
{
FileItem fi = (FileItem)i.next();
if (!fi.isFormField())
{
String fieldName = fi.getFieldName();
String fileName = fi.getName();
String contentType = fi.getContentType();
boolean isInMemory = fi.isInMemory();
long sizeInBytes = fi.getSize();
if(fileName.lastIndexOf("\\") >= 0){
file = new File(filePath +
fileName.substring(fileName.lastIndexOf("\\"))) ;
}else{
file = new File(filePath +
fileName.substring(fileName.lastIndexOf("\\")+1)) ;
}
fi.write(file) ;
out.println("Uploaded Filename: " + fileName + "<br>"+filePath);
}
我的html:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="upload" method="post"
enctype="multipart/form-data">
<input type="file" name="file">
<br />
<select name="sel1">
<option label ="1">aerospace</option>
<option label ="2">automotive</option>
</select>
<select name="sel2">
<option label="1">internal</option>
<option label="2">demo</option>
</select>
<input type="submit" value="Upload File" />
</form>
</body>
</html>
:在烏拉圭回合的答案.getfieldname和.getname將處理輸入type.the同樣會爲下拉工作? – ksa
我發佈的鏈接背後有詳細的例子。 – BalusC
謝謝u.i會盡我所能。 – ksa