生活随笔
收集整理的這篇文章主要介紹了
Response_案例3_输出字节数据
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
服務(wù)器輸出字節(jié)數(shù)據(jù)到瀏覽器
?? ?* 步驟:
?? ??? ?1. 獲取字節(jié)輸出流
?? ??? ?2. 輸出數(shù)據(jù)
package com.learn.web.servlet;import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;@WebServlet("/responseDemo5")
public class ResponseDemo5 extends HttpServlet {protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html;charset=utf-8");//1.獲取字節(jié)輸出流ServletOutputStream sos = response.getOutputStream();//2.輸出數(shù)據(jù)sos.write("你好".getBytes("utf-8"));}protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doPost(request,response);}
}
?
超強干貨來襲 云風(fēng)專訪:近40年碼齡,通宵達旦的技術(shù)人生
總結(jié)
以上是生活随笔為你收集整理的Response_案例3_输出字节数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。