Java 怎么使用servlet响应编写器

2019年8月17日22:02:56 评论 24

1.简介

Java 怎么使用servlet响应编写器?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Main{
    public static void responseWriter(
            HttpServletResponse httpServletResponse, String responseMsg) {
        PrintWriter printWriter = null;
        httpServletResponse.setContentType("text/html");
        httpServletResponse.setCharacterEncoding("UTF-8");
        try {
            printWriter = httpServletResponse.getWriter();
            printWriter.println(responseMsg);
            printWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

3.总结

示例代码演示了 Java 怎么使用servlet响应编写器,具体步骤参见示例代码。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: