软件三班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

相关推荐
手揽回忆怎么睡3 分钟前
java打包无效的发行版:xx,临时修复当前窗口指定 JDK21
java·开发语言
一直有一个ac的梦想14 分钟前
cmu15445 2025fall lec15 query optimiaztion Pt1
java·服务器·数据库
郝学胜-神的一滴14 分钟前
干货版《算法导论》03:动态数组 × 链表的极致平衡艺术
java·数据结构·c++·python·算法·链表
SamDeepThinking16 分钟前
IntelliJ IDEA 中有什么让你相见恨晚的技巧?
java·后端·程序员
SamDeepThinking18 分钟前
为什么选微服务而不是动态扩容单体
java·后端·架构
小新同学^O^27 分钟前
初步了解--> SpringCloud
java·学习·spring·spring cloud
ch.ju43 分钟前
Java程序设计(第3版)第二章——函数的递归
java·开发语言
其实防守也摸鱼1 小时前
ctfshow--Crypto(crypto1-14)解题步骤
java·开发语言·网络·安全·密码学·ctf·ctfshow
Komore3151 小时前
java 泛型
java·开发语言·泛型