好吧,我的任务是在两个应用程序(应用程序)必须上传不同类型的应用程序时上传文件,一个应用程序称为 APA,另一个是 fSCG。当我删除 if APA else SCG 时,如果我使用 if APA else SCG,则代码有效,我得到空错误。请看下面的代码
在我的 JSP 中,代码如下——
<form name="upload" action="/call" enctype= "multipart/form-data" method="POST">
Select file: <input type="file" name="file"/>
<input type="hidden" name="app" value="${app}"/>
<input type="submit" value="Upload"/>
</form>
这是java控制器类
@RequestMapping(value = "/call", method = RequestMethod.POST)
public void process(HttpServletRequest request, HttpServletResponse response) throws Exception {
final String app = request.getParameter("app");
**if (app.equals(APA) {** This is where the error is
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter( );
if (!isMultipart) {
return;
}
out.println("<h2> File is successfully uploaded<h2>");
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
// Parse the request
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField()) {
String fileName = new File(item.getName()).getName();
String uploadFolder = "C:\\Users;
String filePath = uploadFolder + File.separator + fileName;
File uploadedFile = new File(filePath);
item.write(uploadedFile);
}
}
} catch (FileUploadException ex) {
throw new ServletException(ex);
} catch (Exception ex) {
throw new ServletException(ex);
}
}
else if
if (app.equals(SCG)) {** Error here code to upload几乎与上面相同}
为什么我不能用如果应用程序上传请给我一些可能的例子