分析Hello2代碼
阿新 • • 發佈:2019-03-25
response getpara text 服務器 -s con 如果 宋體 lan
代碼如下
String username = request.getParameter("username");
if (username != null && username.length()> 0) {
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/response");
if (dispatcher != null) {
dispatcher.include(request, response);
}
}
out.println("</body></html>");
}
解釋:
String username = request.getParameter("username");//以String的形式返回參數
並賦值給username
if (username != null && username.length()> 0) { //判斷username是否不為null並且長度大於零
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/response");
//
定義接收來自客戶端的請求並將它們發送到服務器上的任何資源的對象dispatcher
if (dispatcher != null) {
dispatcher.include(request, response);
}
如果接收到的客戶端的請求不為空時,記錄保留request和response,以後不能再修改response裏表示狀態的信息
分析Hello2代碼