博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Servlet写hello world
阅读量:4601 次
发布时间:2019-06-09

本文共 1745 字,大约阅读时间需要 5 分钟。

1.声明式开发:

web.xml:

lmj
MyServlet
com.lmj.MyServlet
MyServlet
/hello
index.jsp

MyServlet

public class MyServlet extends HttpServlet {    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {          response.getWriter().write("hello world");    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {         this.doPost(request,response);    }}

pom.xml中添加javax.servlet依赖:

4.0.0
com
servletTest
1.0-SNAPSHOT
javax.servlet
servlet-api
3.0-alpha-1
provided

2.注解式开发:

web.xml:

lmj
index.jsp

MyServlet:

@WebServlet(name = "myServlet", urlPatterns = "/lmj")public class MyServlet extends HttpServlet {    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {          response.getWriter().write("hello world");    }    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {         this.doPost(request,response);    }}

 

转载于:https://www.cnblogs.com/goodshred/p/9782110.html

你可能感兴趣的文章
13、对象与类
查看>>
Sublime Text3 个人使用心得
查看>>
jquery 编程的最佳实践
查看>>
MeetMe
查看>>
IP报文格式及各字段意义
查看>>
(转载)rabbitmq与springboot的安装与集成
查看>>
C2. Power Transmission (Hard Edition)(线段相交)
查看>>
STM32F0使用LL库实现SHT70通讯
查看>>
Atitit. Xss 漏洞的原理and应用xss木马
查看>>
MySQL源码 数据结构array
查看>>
(文件过多时)删除目录下全部文件
查看>>
T-SQL函数总结
查看>>
python 序列:列表
查看>>
web移动端
查看>>
pythonchallenge闯关 第13题
查看>>
linux上很方便的上传下载文件工具rz和sz使用介绍
查看>>
React之特点及常见用法
查看>>
【WEB前端经验之谈】时间一年半,或沉淀、或从零开始。
查看>>
优云软件助阵GOPS·2017全球运维大会北京站
查看>>
linux 装mysql的方法和步骤
查看>>