hello2源代码分析

String username = request.getParameter("username");
/*
*以 String 形式返回请求参数"username"的值,并赋值给username,如果该参数不存在,则返回 null。
*请求参数是与请求一起发送的额外信息。
*对于 HTTP servlet,参数包含在查询字符串或发送的表单数据中。
*/
if (username != null && username.length()> 0) {//若username不为null并且长度大于零则
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/response");
          /*
           *定义接收来自客户端的请求并将它们发送到服务器上的任何资源的对象dispatcher
           *该对象被用作包装位于特定路径上的服务器资源或通过特定名称给定的服务器资源的包装器。
          */
          

if (dispatcher != null) {
dispatcher.include(request, response);
}
}

@WebServlet("/response")
public class ResponseServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
try (PrintWriter out = response.getWriter()) {

// then write the data of the response
String username = request.getParameter("username");
if (username != null && username.length()> 0) {
out.println("<h2>Hello, " + username + "!</h2>");
}
}
}

转载于:https://www.cnblogs.com/hhhkai/p/10590372.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值