【servlet】 第一个servlet

简单打印haha

 

Helloyt.java

package day01;



import java.io.IOException;



import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;



public class Helloyt extends HttpServlet{

    public void init(ServletConfig config) throws ServletException{

        super.init(config);

    }

    

    public void doGet(HttpServletRequest req,HttpServletResponse resp)

    throws IOException,ServletException{

        doPost(req,resp);

    }

    

    public void doPost(HttpServletRequest req,HttpServletResponse resp)

            throws IOException,ServletException{

        resp.setContentType("text/html;charset=utf-8");

        resp.getOutputStream().println("hehe");

//        resp.getWriter().println("haha");

         

    } 

    

    public void destroy(){

        super.destroy();

    }    

}

 

 

 

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0"

    xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

  

  <servlet>

    <servlet-name>helloyt</servlet-name>

    <servlet-class>day01.Helloyt</servlet-class>

  </servlet>



  <servlet-mapping>

    <servlet-name>helloyt</servlet-name>

    <url-pattern>/helloyt</url-pattern>

  </servlet-mapping>



</web-app>

 

你可能感兴趣的:(servlet)