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
	}

}
最近下载更多
刘卫国  LV6 2021年12月1日
_M*  LV11 2021年5月12日
909074489  LV34 2017年6月28日
yuanjiayuanit  LV2 2017年5月18日
prime2015  LV14 2016年12月10日
seasuka  LV15 2016年6月26日
最代码官方  LV167 2016年5月24日
最近浏览更多
操作者 4月10日
暂无贡献等级
yjdang  LV3 2023年3月27日
小逸夜  LV4 2022年12月24日
taoshen95  LV15 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日
Andy095 2022年1月29日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友