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

相关推荐
茶本无香27 分钟前
@Scheduled(cron = “0 */5 * * * ?“) 详解
java·定时任务·scheduled
yaonoran29 分钟前
【无标题】
java·开发语言·变量
康小庄35 分钟前
浅谈Java中的volatile关键字
java·开发语言·jvm·spring boot·spring·jetty
vx_bisheyuange37 分钟前
基于SpringBoot的海鲜市场系统
java·spring boot·后端·毕业设计
康康的AI博客44 分钟前
工业数据中台:PLC、SCADA、MES的实时协同架构
java·服务器·网络
それども1 小时前
为什么要加@ResponseBody
java·开发语言·spring boot
一只专注api接口开发的技术猿1 小时前
微服务架构下集成淘宝商品 API 的实践与思考
java·大数据·开发语言·数据库·微服务·架构
2501_944424121 小时前
Flutter for OpenHarmony游戏集合App实战之记忆翻牌配对消除
android·java·开发语言·javascript·windows·flutter·游戏
鹿角片ljp1 小时前
Java网络编程入门:从Socket到多线程服务器
java·服务器·网络
走进IT2 小时前
DDD项目分层结构说明
java