编写一个简单的Servlet程序,通过Servlet向浏览器输出文本信息“好好学习,天天向上”。要求写出相应的Servlet及其配置文件(要注意乱码问题的解决)。 注意写出标识位置的代码即可 public class print extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //servlet代码书写开始 [br][/br] [br][/br] [br][/br] [br][/br] [br][/br] //servlet代码书写结束 } } 配置文件
举一反三
- 给定一个Servlet的代码片段如下: Public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{ ______ out.println("hi kitty! "); out.close(); } 运行Servlet时输出:hi kitty! 则应在此Servlet下划线处填充如下代码
- LoginServlet是一个Servlet类,代码如下 public class LoginServlet extends ___________ { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { … } public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { … } } 在下划线处应填写()
- 智慧职教: 在Servlet中有如下代码段: public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dis; _____________________________; dis.forward(request,response); }
- 给定某Servlet的代码如下: Public class Servlet1 extends HttpServlet{ Public void init() throws ServletException{ } Public void service(HttpServletRequest request,HttpServletResponse response) ThrowsServletException,IOException{ PrintWriter out = response.getWriter(); <br/>out.println(“hello!”); }} 编译运行该文件,以下陈述正确的是()。 A: 编译该文件时会提示缺少doGet()或者dopost()方法,编译不能够成功通过 B: 编译后,把Servlet1.class放在正确位置,运行该Servlet,在浏览器中会看到输出文字: C: 编译后,把Servlet1.class放在正确位置,运行该Servlet,在浏览器中看不到任何输出 D: 编译后,把Servlet1.class放在正确位置,运行该Servlet,在浏览器中会看到运行期错误
- 阅读下列的代码 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{ out.println("hello kity!"); } 若使Servlet运行的结果为hi kitty!,填写在空白处的代码为() 则应在此Servlet下划线处添加如下()代码