gpt4 book ai didi

java - 预计出现编译错误

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

所以这可能很简单,但我仍然无法自己解决。这是什么意思?

GET.java:27: error: <identifier> expected
out.println("</p></body></html>");
^
GET.java:27: error: illegal start of type
out.println("</p></body></html>");

这是我的 java servlet 的代码:

  import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class GET extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
FileOutputStream fos = new FileOutputStream("/tmp/prdocutorders.txt");
PrintWriter pw = new PrintWriter(fos);
out.println("<html><body><p>");
pw.println("<h3>Congratulations! Your order information:</h3>");
Enumeration e = req.getParameterNames();
while ( e.hasMoreElements() ) {
String name = (String)e.nextElement();
String vals[] = (String[])req.getParameterValues(name);
if ( vals != null )
for (int i = 0; i < vals.length; i++)
out.println(name + ": " + vals[i] + "<br>");
}
if ( vals != null )
for (int i = 0; i < vals.length; i++)
pw.println(name + ": " + vals[i] + "<br>");
}
out.println("</p></body></html>");
// out.close();
}

感谢您的帮助!!

最佳答案

平衡支架是强制性的。您在语句 out.println("</p></body></html>"); 之前丢失了大括号

顺便说一句,这样更容易发现这样的错误

  • 始终使用大括号
  • 正确缩进代码
<小时/>

编辑:代码的某些部分似乎不正确,您可能需要这样:

while (e.hasMoreElements()) {
String name = (String) e.nextElement();
String vals[] = (String[]) req.getParameterValues(name);
if (vals != null) {
for (int i = 0; i < vals.length; i++) {
out.println(name + ": " + vals[i] + "<br>");
pw.println(name + ": " + vals[i] + "<br>");
}
}
}
out.println("</p></body></html>");

关于java - 预计出现编译错误 <identifier>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26659082/

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