首页 > 其他 > 详细

Servlet

时间:2019-07-15 20:24:56      阅读:90      评论:0      收藏:0      [点我收藏+]
package org.west.demo;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ServletTest extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("nihao servlet");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      doPost(request,response);
    }
}

配置web

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <servlet>
        <servlet-name>ServletTest</servlet-name>
        <servlet-class>org.west.demo.ServletTest</servlet-class>
    </servlet>
  <!--========================================================================-->



    <servlet-mapping>
        <servlet-name>ServletTest</servlet-name>
        <url-pattern>/test01</url-pattern>
    </servlet-mapping>
</web-app>

这样我们通过网页和服务器就可以在控制台进行交互了。

Servlet

原文:https://www.cnblogs.com/xiaoqiqistudy/p/11191086.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!