import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class WriteServlet extends HttpServlet { /** * Constructor of the object. */ public WriteServlet() { super(); } /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String text = request.getParameter("text"); String savePath = request.getParameter("savePath"); FileOutputStream fos = new FileOutputStream(savePath); fos.write(text.getBytes("UTF-8")); fos.flush(); fos.close(); PrintWriter out = response.getWriter(); out.print("write ok!"); out.flush(); out.close(); } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } }


hulewang LV8
2024年10月12日
操作者
2024年4月10日
暂无贡献等级
yjdang LV3
2023年3月27日
小逸夜 LV4
2022年12月24日
taoshen95 LV16
2022年12月19日
1442433742 LV1
2022年12月7日
and123456 LV11
2022年10月26日
yinyun1985 LV14
2022年4月11日
xwmxwm LV4
2022年4月7日
fengshengtian LV8
2022年3月7日