Servlet的基本架构
public class ServletName extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
}
}
1、用String的方法将数据类型转换为String。
1、String.valueOf(1.23)
第1题:
下列______选项不是InputStream类中的方法。
A.public abstract int read() throws IOException
B.public final void writeInt (int V)throws IOException
C.public int available() throws IOException
D.public void close() throws IOException
第2题:
下列哪个选项不是InputStream类中的方法? ( )
A.public abstract int read()throws IOException
B.public final void writeInt(int v)throws IOException
C.public void close()throws IOException
D.public int available()throws IOException
第3题:
在J2EE中,给定某Servlet的代码如下,编译运行该文件,以下陈述正确的是( )
public class Servletl extends HttpServlet{
public void init() throws ServletException{
}
public void service(HttpServletRequest
request,HttpServletResponse response)throws
ServletException,IOException{
PrintWriter ut=response.getWriter();
out.println(“hello!”);
}
}
A、编译该文件时会提示缺少doGet()或者doPost()方法,编译不能够成功通过
B、编译后,把Servletl.class放在正确位置,运行该Servlet,在浏览器中会看到输出文字:hello!
C、编译后,把Servletl.class放在正确位置,运行该Servlet,在浏览器中会看不到任何输出的文字
D、编译后, 把Servletl.class放在正确位置,运行该Servlet,在浏览器中会看到运行期错误信息
第4题:
在J2EE中,有如下代码在Servlet1.java中。 import javax.servlet.*; import javax.servlet.http.*; import java.io.IOException; import java.io.PrintWriter; public class Servlet1 extends HttpServlet { public void init() throws ServletException { } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("hello!"); } } 假如编译Servlet要具备的环境都已经建立好。现在用完全正确的命令编译该文件,对于以下陈述正确的是()。
第5题:
下面哪个方法不是HttpServlet类:()
第6题:
下面的代码中方法unsafe()有异常发生,那么可以加在第一行的语句为( )。 { if(unsafe()) { //do something } else if(safe()) { //do the other) } Ⅰ:public void methodName() Ⅱ:public void methodName() throw IOException Ⅲ:public void methodName() throws IOException Ⅳ:public void methodName() throws Exception
A.Ⅲ、Ⅳ
B.Ⅱ、Ⅲ、Ⅳ
C.Ⅰ、Ⅲ
D.Ⅰ、Ⅳ
第7题:
public class SomeException { } Class a: public class a { public void doSomething() { } } Class b: public class b extends a { public void doSomething() throws SomeException { } } Which is true about the two classes?()
第8题:
给定某servlet 程序的片段,如下:
Public void doGet(HttpServletRequest
request,Httpservletresponse response)
{
_________
}
要把session的失效时间设为30分钟,应该在下划线处插入( )
A、request.getSession().setTimeout(1800);
B、request.getSession().setTimeout(30)
C、request.getSession().setMaxInactiveInterval(1800);
D、request.getSession().setMaxInactiveInterval(30);
第9题:
在J2EE中,有如下代码在Servlet1.Java中 Import javax.servlet.*; Import javax.servlet.http.* Import java.io.IOException; Import java.io.PrintWriter; Public class Servlet1 extends HttpServlet{ Public void init () throw ServletException {} Public void service(HttpServletRequest request, HttpServletResponce response) throws ServletException,IOException{ PrintWriter out=response.getWriter(); Out.println(“hello!”); } } 假如编译Servlet要具备的环境都已经建立好。现在用完全正确的命令编译该文件,对于以下成熟正确的是()
第10题:
在J2EE中,Servlet1的代码如下: import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Servlet1 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String aa=request.getQueryString(); String bb=request.getMethod(); out.println(aa); out.println(bb); } } 把Servlet1.class文件放在Web服务器适合的目录下,在浏览B器地址栏内输入:http://localhost:8080/servlet/Servlet1?name=jb-aptech&phone=12345678,看到的结果是()。