当前位置:网站首页>模拟Servlet的本质
模拟Servlet的本质
2022-07-07 14:15:00 【Vayne的胖虎子】
项目的目录结构
---src
---web.properties
---javax.servlet
---Servlet
---web
---Tomcat
---service
---UserListServlet
---UserLoginServlet
- web.properties
/aaa=service.UserListServlet
/bbb=service.UserLoginServlet
- Servlet
package javax.servlet;
/** * Author:LinYue * Time:2022-06-27 10:29:54 */
public interface Servlet {
void service();
}
- Tomcat
package web;
import javax.servlet.Servlet;
import java.util.ResourceBundle;
import java.util.Scanner;
/** * Author:LinYue * Time:2022-06-27 10:32:13 */
public class Tomcat {
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
System.out.println("Tomcat启动了....");
Scanner s = new Scanner(System.in);
System.out.print("请输入访问路径:");
String path = s.nextLine();
ResourceBundle bundle = ResourceBundle.getBundle("web");
String resource = bundle.getString(path);
Class clazz = Class.forName(resource);
Object obj = clazz.newInstance();
Servlet servlet = (Servlet) obj;
servlet.service();
}
}
- UserListServlet
package service;
import javax.servlet.Servlet;
/** * Author:LinYue * Time:2022-06-27 10:31:06 */
public class UserListServlet implements Servlet {
@Override
public void service() {
System.out.println("UserListServlet的service方法调用了!");
}
}
- UserLoginServlet
package service;
import javax.servlet.Servlet;
/** * Author:LinYue * Time:2022-06-27 10:31:06 */
public class UserLoginServlet implements Servlet {
@Override
public void service() {
System.out.println("UserLoginServlet的service方法调用了!");
}
}
边栏推荐
- 47_Opencv中的轮廓查找 cv::findContours()
- 01tire+链式前向星+dfs+贪心练习题.1
- IP地址和物理地址有什么区别
- Continuous creation depends on it!
- 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
- Set the route and optimize the URL in thinkphp3.2.3
- Numpy -- data cleaning
- Plate - forme de surveillance par étapes zabbix
- Numpy --- basic learning notes
- Sysom case analysis: where is the missing memory| Dragon lizard Technology
猜你喜欢
【Android -- 数据存储】使用 SQLite 存储数据
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
TiDB For PostgreSQL和YugabyteDB在Sysbench上的性能对比
You Yuxi, coming!
Step by step monitoring platform ZABBIX
Unity3d click events added to 3D objects in the scene
Power of leetcode-231-2
Talk about the cloud deployment of local projects created by SAP IRPA studio
Leetcode-231-2的幂
融云斩获 2022 中国信创数字化办公门户卓越产品奖!
随机推荐
记一次项目的迁移过程
Set the route and optimize the URL in thinkphp3.2.3
Laravel5.1 路由 -路由分组
Laravel 中config的用法
Detailed explanation of several ideas for implementing timed tasks in PHP
leetcode 241. Different Ways to Add Parentheses 为运算表达式设计优先级(中等)
删除 console 语句引发的惨案
A link opens the applet code. After compilation, it is easy to understand
Enterprise log analysis system elk
喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
模仿企业微信会议室选择
IP地址和物理地址有什么区别
Continuous creation depends on it!
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
Logback日志框架第三方jar包 免费获取
PHP has its own filtering and escape functions
Balanced binary tree (AVL)
JS modularization
Migration and reprint