import java.io.BufferedReader; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; public class Debug extends HttpServlet { @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("
"); int len = request.getContentLength(); char[] buf = new char[len]; File f = new File(getServletContext().getRealPath("/Debug.out")); PrintWriter fout = new PrintWriter(new FileWriter(f)); BufferedReader in = request.getReader(); in.read(buf); in.close(); fout.print(buf); fout.close(); out.printf("CONTENT_LENGTHは %dです。%n", len); out.println("Debug.outに情報を書きこみました。"); out.println(""); out.close(); } }