gpt4 book ai didi

java - 使用 Java EE 上传文件错误

转载 作者:行者123 更新时间:2023-12-01 12:08:05 25 4
gpt4 key购买 nike

以下代码正在读取错误消息。特别是,当我输入 Java 代码时,它似乎不会被识别为 Java。例如,它不会自动缩进。我正在使用 JavaServer Faces。有人知道我哪里出错了吗?

<%@page import="java.io.*"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Page</title>
</head>
<body bgcolor="#2e8b57">
<table style="width:100%">
<tr>
<td colspan="1">
</td>
</tr>
<tr>
<td style="width: 40%"><img src="image.JPG" width="700" height="550"
alt="image2"/></td>
<td style="width: 40%"><font color="white" size="4"><br><b>text goes here</b><br>
<br>text goes here</font></a></td>
</tr>
<tr>
<td colspan="1">
</td>
</tr>

</table>

<form name="uploadForm" action="index.jsp" method="POST" enctype="multipart/form-
data">
<%
String saveFile = new String();
String contentType = request.getContentType();
if((contentType != null) && (contentType.indexOf("multipart/form-data")>=0)){
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte(formDataLength[]);
int byteRead = 0;
int totalBytesRead = 0;
while(totalBytesRead<formDataLength){
byteRead = in.read(dataBytes, totalBytes, totalBytesRead, formDataLength);
totalBytesREad +=byteRead;
}
String file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\n")+10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+1, saveFile.indexOf("\""));

int lastIndex = contentType.lastIndexOf("-");
String boundary = contentType.substring(lastIndex + 1, contentType.length();
int pos;

pos = file.indexOf("filename=\" ");
pos = file.indexOf("\n", pos)+ 1;
pos = file.indexOf("\n", pos)+ 1;
pos = file.indexOf("\n", pos)+ 1;

int startPos = ((file.substring(0, pos).getBytes().length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes)).length;
}
}



%>
<input type="file" name="file" value="" />
<input type="submit" value="Submit" name="submit" />
</form>


</body>
</html>

错误日志如下。第 43 行是包含 <% :

的行
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
'[' expected

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
illegal start of expression

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
')' expected

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
')' expected

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

PWC6197: An error occurred at line: 43 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
not a statement

PWC6199: Generated servlet error:
'try' without 'catch' or 'finally'

PWC6199: Generated servlet error:
illegal start of type

PWC6199: Generated servlet error:
illegal start of type

PWC6199: Generated servlet error:
';' expected

PWC6199: Generated servlet error:
<identifier> expected

PWC6199: Generated servlet error:
<identifier> expected

PWC6199: Generated servlet error:
class, interface, or enum expected

最佳答案

您可能缺少<%@ page language="java"contentType="text/html; charset=ISO-8859-1"%>。您的 JSP 中还存在需要修复的编译问题(缺少括号等)。

谢谢阿维 git

关于java - 使用 Java EE 上传文件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27447703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com