请求转发时候我们使用的是RequestDispather对象,假设当前包为test,有servlet1和servlet2。下面从servlet1跳转到servlet2的写法正确的是( )
A: RequestDispatcher rd=context.getRequestDispatcher ("servlet2");
B: RequestDispatcher rd=context.getRequestDispatcher ("/servlet2");
C: RequestDispatcher rd=context.getRequestDispatcher ("test/servlet2");
D: RequestDispatcher rd=context.getRequestDispatcher ("/test/servlet2");
A: RequestDispatcher rd=context.getRequestDispatcher ("servlet2");
B: RequestDispatcher rd=context.getRequestDispatcher ("/servlet2");
C: RequestDispatcher rd=context.getRequestDispatcher ("test/servlet2");
D: RequestDispatcher rd=context.getRequestDispatcher ("/test/servlet2");
举一反三
- 在Java Web应用程序中,包含两个名为Servlet1和Servlet2的HttpServlet,在web.xml中指定Servlet2的访问路径为“/Servlet2”,Servlet1的doGet方法中的代码为:[br][/br]PrintWriter out = response.getWriter();[br][/br]out.print (“Servlet”); ______________ context = getServletContext(); RequestDispatcher dispatcher = context.____________(“/servlet2”); [br][/br]dispatcher.___________(____________,response);[br][/br]out.close();[br][/br]Servlet2的doGet方法中的代码为:[br][/br]PrintWriter out = response.getWriter();[br][/br]out.print(“Servlet2”);[br][/br]out.close();[br][/br]如果用户在浏览器中访问Servlet1,则浏览器显示内容为:__________________________
- 阅读下面代码片段: Servlet1: response.setContentType("text/html;charset=gbk"); response.getWriter().write("传播智慧"); request.getRequestDispatcher("/servlet/Servlet2") .forward(request,response); response.sendRedirect("/app/servlet/Servlet3"); Servlet2: response.getWriter().write("收获成长"); 请问当浏览器访问Servlet1时会有什么样的输出
- 【单选题】有如下一些映射关系: /abc/* 映射到Servlet1 /* 映射到Servlet2 /abc 映射到Servlet3 *.do 映射到Servlet4 当请求URL为“/abc”时,将会执行哪个Servlet A. Servlet1 B. Servlet2 C. Servlet3 D. Servlet4
- 在servlet1中的doGet和doPost方法中只有如下代码: request .setAttribute("jb","aPtech"); response .sendRedirect("http://localhost:8080/servlet/Servlet2"); 那么在Servlet2 中使用( )可以把属性jb的值取出来。
- 阅读下面代码片段: Servlet1: response.setCharacterEncoding("utf-8"); response.setHeader("Content-Type", "text/html;charset=utf-8"); response.getWriter().write("传播"); request.getRequestDispatcher("/servlet/Servlet2") .forward(request,resp onse); Servlet2: response.getWriter().write("智慧"); request.getRequestDispatcher("/servlet/Servlet3") .forward(request,response); response.setHeader("Content-Type", "text/html;charset=iso8859-1"); Servlet3: response.getWriter().write("挥洒汗水"); 请问当浏览器访问Servlet1时会有什么样的输出: