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

相关推荐
冉冰学姐18 小时前
基于ssm的技能比赛报名管理系统29817vn0(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面
java·数据库·spring·ssm 框架应用
代码雕刻家21 小时前
3.5.Maven-依赖管理-依赖配置&依赖传递
java·maven
!chen21 小时前
MyBatis-plus拓展之字段类型处理器、自动填充和乐观锁
java·tomcat·mybatis
Jin、yz21 小时前
JAVA 八股
java·开发语言
va学弟1 天前
Java 网络通信编程(6):视频通话
java·服务器·网络·音视频
pjw198809031 天前
Spring Framework 中文官方文档
java·后端·spring
jgyzl1 天前
2026.3.11MyBatis-Plus基本使用与思考
java·数据库·mybatis
Full Stack Developme1 天前
Java 常用通信协议及对应的框架
java·开发语言
( •̀∀•́ )9201 天前
Spring Boot 启动报错 `BindException: Permission denied`
java·spring boot·后端
杰克尼1 天前
苍穹外卖--day10
java·数据库·spring boot·mybatis·notepad++