zoukankan      html  css  js  c++  java
  • 第一个servlet程序

    费了很大一股劲;

    Servlet.java

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class ServletTest extends HttpServlet {
    
        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            response.setHeader("Content-Type", " text/html; charset=utf-8");
            response.getWriter().println("庞静赢是个傻逼");
        }
    }
    View Code

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
      <display-name>test</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
      
     <servlet>
         <servlet-name> ServletTest</servlet-name>
         <servlet-class>ServletTest</servlet-class>
     </servlet>
    
     <servlet-mapping>
           <!-- 映射Servlet -->
           <servlet-name>ServletTest</servlet-name>
           <!--<servlet-name>与上面<Servlet>标签的<servlet-name>元素相对应,不可以随便起名  -->
           <url-pattern>/ServletTest</url-pattern>
           <!-- 上面一句话用于映射访问URL -->
       </servlet-mapping>
    </web-app>
    View Code

    加油!

  • 相关阅读:
    简明python_Day2_字典、集合、模块、类、编程习惯
    测试2T2
    测试2T1
    bzoj2761
    一元三次方程求根公式及韦达定理
    状压DP入门——铺砖块
    高精度模板
    测试1T3
    测试1T2
    测试1T1
  • 原文地址:https://www.cnblogs.com/helloworld2019/p/10841605.html
Copyright © 2011-2022 走看看