⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 welcomeservlet.java

📁 提供 精通Java Web动态图表编程 一书的源代码, 大家赶快下载呀
💻 JAVA
字号:
// Fig. 5.02_01: WelcomeServlet.java
// 简单地处理客户端 get	请求的 servlet

package com.fatcat.webchart;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class WelcomeServlet extends HttpServlet {   

   // 处理客户端的 "get" 请求
   protected void doGet( HttpServletRequest request, 
      HttpServletResponse response )
         throws ServletException, IOException 
   {
      response.setContentType( "text/html;charset=gb2312" );
      PrintWriter out = response.getWriter();  
      
      // 发送 XHTML 格式的页面给客户端

      // 开始生成 XHTML 文档
      out.println( "<?xml version = \"1.0\"?>" );

      out.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD " +
         "XHTML 1.0 Strict//EN\" \"http://www.w3.org" +
         "/TR/xhtml1/DTD/xhtml1-strict.dtd\">" ); 

      out.println( "<html xmlns = \"http://www.w3.org/1999/xhtml\">" );
      
      // 生成文档的head部分
      out.println( "<head>" );
      out.println( "<title>简单地处理客户端\"get\"请求的servlet</title>" );
      out.println( "</head>" );
      
      // 生成文档的body部分
      out.println( "<body>" );
      out.println( "<h1>您好,<br>欢迎进入Servlet图表编程的世界</h1>" );
      out.println( "</body>" );
      
      // 结束 XHTML 文档
      out.println( "</html>" );
      out.close();  // 关闭输出流
   }   
}

/**************************************************************************
 * (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓).  *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors of this code have used their                   *
 * best efforts in preparing the code. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these codes. The authors *
 * shall not be liable in any event for incidental or consequential       *
 * damages in connection with, or arising out of, the furnishing,         *
 * performance, or use of these programs.                                 *
 **************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -