hello2 source analysis

String username = request.getParameter("username");                        ||通过url或者form传递过来的值赋值给username,比如说username是客户端用户输入的内容,然后把这个内容赋值给username.
            if (username != null && username.length()> 0) {                ||判断值是否为空并且长度大于0
                RequestDispatcher dispatcher =
                    getServletContext().getRequestDispatcher("/response"); ||请求重定向转发到指定URL "/"代表相对与web应用路径
(把一个命令发送到浏览器,让浏览器对在location中指定的URL提出请求。
该方法可以接受绝对的或相对的URLs。
如果传递到该方法的参数是一个相对的URL,那么Web container在将它发送到客户端前会把它转换成一个绝对的URL。
如果地址是相对的,没有一个’/’,那么Web container就认为它是相对于当前的请求URI的。)
if (dispatcher != null) { dispatcher.include(request, response); } } out.println("</body></html>"); } }
利用include()方法将HTTP请求转送给其他Servlet后,被调用的Servlet虽然可以处理这个HTTP请求,但是最后的主导权仍然是在原来的Servlet。换言之,被调用的Servlet如果产生任何HTTP回应,将会并入原来的HttpResponse对象。

猜你喜欢

转载自www.cnblogs.com/clling/p/10577263.html
今日推荐