软件三班20240605

文章目录

  • 1.创建工程和模块
  • 2.添加 web支持
  • 3.创建前端代码
  • 4.添加servlet 依赖
    1. 代码
  • 6.案例2

1.创建工程和模块


2.添加 web支持

  • 方法1


  • 方法2

3.创建前端代码



4.添加servlet 依赖





5. 代码

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<a href="/test/demo">启动服务</a>
<!--  超链接  =     一个 url  -->
</body>
</html>
xml 复制代码
<?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>aa</servlet-name>
        <servlet-class>com.yanyu.Demo</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>aa</servlet-name>
        <url-pattern>/test/demo</url-pattern>
    </servlet-mapping>



</web-app>
java 复制代码
package com.yanyu;

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

public class Demo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        设置  编码  格式和  响应的内容
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
//      获取  响应对象
        PrintWriter out = response.getWriter();//  ctrl   alt   v
        System.out.println("ergrthuj1233");
        out.print("前端测试");




    }
}

6.案例2

相关推荐
yaoxin5211233 分钟前
381. Java IO API - 控制文件树遍历流程
java·开发语言
SimonKing4 分钟前
OpenCode 20 个斜杠命令,90% 的人只用过 3 个
java·后端·程序员
尽兴-4 分钟前
Spring与Dubbo整合原理与源码分析
java·spring·dubbo·enabledubbo
Gopher_HBo5 分钟前
BlockingQueue详解
java·后端
白露与泡影5 分钟前
为什么在IDEA使用@Autowired会报黄?
java·ide·intellij-idea
我登哥MVP7 分钟前
【Spring6笔记】 - 15 - Spring中的八大设计模式
java·spring boot·笔记·spring·设计模式·intellij-idea
蚰蜒螟13 分钟前
深入剖析 Tomcat 9.0.53 源码:Web 资源管理与类加载机制
java·前端·tomcat
m0_4750645017 分钟前
Spring AI文档切片
java·人工智能·spring
我登哥MVP17 分钟前
【SpringMVC笔记】 - 1 - SpringMVC入门
java·spring boot·spring·tomcat·maven·intellij-idea·springmvc
Arva .20 分钟前
Spring 事务传播机制 速记
java·数据库·spring