当前位置:网站首页>20220209创建一个基础的servlet
20220209创建一个基础的servlet
2022-07-18 18:06:00 【翟小花@@】
20220209创建一个基础的servlet
创建一个类或者直接右键创建servlet
形成目录如图
写doGet方法
ServletDemo1.java
package com.helloservlet.hello;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletDemo1 extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("接收HTTP的GET方式请求");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doPost(req, resp);
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
super.service(req, resp);
}
}
配置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_4_0.xsd"
id="WebApp_ID" version="4.0">
<display-name>project20220209</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- 配置servlet -->
<servlet>
<!-- servlet别名 -->
<servlet-name>demo1</servlet-name>
<servlet-class>com.helloservlet.hello.ServletDemo1</servlet-class>
</servlet>
<!-- 配置servlet映射 -->
<servlet-mapping>
<servlet-name>demo1</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
按照xml文件欢迎页应该是index.html,所以访问时会出现index.html的内容,但是设置了servlet拦截,所以进入到servlet的doGet方法中,而不会显示index.html的内容
边栏推荐
猜你喜欢
Three handshakes and four waves
Scrapy去重
网络安全相关证书有哪些?
openstack云平台搭建与使用
Enterprise publicity 720vr panoramic display optimizes online marketing experience
Student management system - IO flow
Redis method cache
牛客sql第八题 SELECT DISTINCT
What are the differences between cisp-pte and cisaw certification?
项目实战01-openpyxl读取Excel
随机推荐
What are the directions of CISP?
Scrapy去重
LNMP+Wordpress快速搭建个人网站
linux安装redis(centos7)
牛客sql题第七题——group by和having
List集合
Redis method cache
Is the CISA certificate rich in gold?
Introspection as a technology developer (year-end summary)
How to realize vr virtual reality display
盘点信息安全CISP家族热门认证
CISP能线上考试吗?
Heilongjiang digital twin smart park construction, comprehensive integration of internal and external resources in the park
Makefile生成 静态链接库万能模板(当前文件夹、递归全部文件夹编译成.a)
2022-07-12 group 5 Gu Xiangquan's learning notes day05
安装JumpServer如何解决MarkupSafe-1.0安装不成功
(Network Engineer) hcna - NP full Huawei (Router, switch) Configuration full, Self - Summary Notes
Getting started with uni app
JVM和GC学习总结
IO流——内存流、对象流