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

📄 hello.java

📁 164个完整的Java程序源代码,包括了19种Java技术的164个类源代码
💻 JAVA
字号:
/* * Copyright (c) 2000 David Flanagan.  All rights reserved. * This code is from the book Java Examples in a Nutshell, 2nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit http://www.davidflanagan.com/javaexamples2. */package com.davidflanagan.examples.servlet;import javax.servlet.*;         // Basic servlet classes and interfacesimport javax.servlet.http.*;    // HTTP specific servlet stuffimport java.io.*;               // Servlets do IO and throw IOExceptions/** * This simple servlet greets the user.  It looks in the request and session * objects in an attempt to greet the user by name. **/public class Hello extends HttpServlet {    // This method is invoked when the servlet is the subject of an HTTP GET    public void doGet(HttpServletRequest request, HttpServletResponse response)        throws IOException    {	// See if the username is specified in the request	String name = request.getParameter("username");	// If not, look in the session object.  The web server or servlet	// container performs session tracking automatically for the servlet,	// and associates a HttpSession object with each session.	if (name == null) 	    name = (String)request.getSession().getAttribute("username");	// If the username is not found in either place, use a default name.	if (name == null) name = "World";	// Specify the type of output we produce.  If this servlet is	// included from within another servlet or JSP page, this setting	// will be ignored.	response.setContentType("text/html");	// Get an stream that we can write the output to	PrintWriter out = response.getWriter();	// And, finally, do our output.	out.println("Hello " + name + "!");    }    // This method is invoked when the servlet is the subject of an HTTP POST.    // It calls the doGet() method so that this servlet works correctly    // with either type of request.    public void doPost(HttpServletRequest request,HttpServletResponse response)        throws IOException    {	doGet(request, response);    }}

⌨️ 快捷键说明

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