假设在myServlet应用中有一个MyServlet类,在web文件中对其进行如下配置myservlethaut.servlet.MyServletmyservlet/welcome下列可以访问到Servlet是()
A. http://localhost:8080/MyServlet
B. http://localhost:8080/mservlet
C. http://localhost:8080/haut/servlet/MyServlet
D. http://localhost:8080/welcome
查看答案
当一个请求到达servlet时,响应用户的请求,下列方法一定会调用的方法是()。
A. service()
B. init()
C. doPost()
D. destroy()
现定义有一servlet: exam.ShowNumber,代码如下。package exam;@WebServlet("/ShowNumber")public class ShowNumber extends HttpServlet {private static final long serialVersionUID = 1L;public void service(HttpServletRequest req, HttpServletResponse resp)throws IOException {resp.setContentType("text/html;charset=GBK");PrintWriter out = resp.getWriter();String cmd = req.getParameter("cmd");out.println("");int sum=0;if (cmd.equals("odd")) {for (int i=0;i<10;i++) {if (i % 2!=0) out.print(i+" ");}} else {for (int i=0;i<10;i++) {if (i % 3==0) {out.print(i+" ");sum += i;}}out.println("sum="+sum);}out.println("
");out.println("");}}在浏览器地址栏内输入请求:http://localhost:8080/exam/ShowNumber?cmd=odd, 则浏览器显示结果:( )
A. 0 3 6 9 sum=18
B. 0 3 6 9
C. 1 3 5 7 9 sum=25
D. 1 3 5 7 9
现定义有一servlet: exam.ShowNumber,代码如下。package exam;@WebServlet("/ShowNumber")public class ShowNumber extends HttpServlet {private static final long serialVersionUID = 1L;public void service(HttpServletRequest req, HttpServletResponse resp)throws IOException {resp.setContentType("text/html;charset=GBK");PrintWriter out = resp.getWriter();String cmd = req.getParameter("cmd");out.println("");int sum=0;if (cmd.equals("odd")) {for (int i=0;i<10;i++) {if (i % 2!=0) out.print(i+" ");}} else {for (int i=0;i<10;i++) {if (i % 3==0) {out.print(i+" ");sum += i;}}out.println("sum="+sum);}out.println("
");out.println("");}}在浏览器地址栏内输入请求:http://localhost:8080/exam/ShowNumber?cmd=, 则浏览器显示结果:( )
A. 0 3 6 9 sum=18
B. 0 3 6 9
C. 1 3 5 7 9 sum=25
D. 1 3 5 7 9
位于web服务目录下的index.jsp文件,通过表单请求myservlet.control.MajorHandler,其表单如下
A. MajorHandler
B. MajorHandler.calss
C. myservlet.control.MajorHandler
D. myservlet.control.MajorHandler.class