当前位置:网站首页>模拟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方法调用了!");
}
}
边栏推荐
- Continuous creation depends on it!
- What is the difference between IP address and physical address
- PHP实现微信小程序人脸识别刷脸登录功能
- Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
- Numpy --- basic learning notes
- 星瑞格数据库入围“2021年度福建省信息技术应用创新典型解决方案”
- 删除 console 语句引发的惨案
- Mysql database backup script
- 【知识小结】PHP使用svn笔记总结
- Asyncio concept and usage
猜你喜欢

过度依赖补助,大客户收款难,冲刺“国产数据库第一股”的达梦后劲有多足?

Sysom case analysis: where is the missing memory| Dragon lizard Technology

Wireless sensor networks -- ZigBee and 6LoWPAN

torch. Numel action

The unity vector rotates at a point

平衡二叉树(AVL)

Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?

Shandong old age Expo, 2022 China smart elderly care exhibition, smart elderly care and aging technology exhibition

Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping

SPI master RX time out interrupt
随机推荐
Application example of infinite list [uigridview]
Performance measure of classification model
AE learning 01: AE complete project summary
Vs tool word highlight with margin
Usage of config in laravel
统计学习方法——感知机
95. (cesium chapter) cesium dynamic monomer-3d building (building)
企业级日志分析系统ELK
laravel 是怎么做到运行 composer dump-autoload 不清空 classmap 映射关系的呢?
Numpy -- data cleaning
Is it reliable to open an account on Tongda letter with your mobile phone? Is there any potential safety hazard in such stock speculation
分步式監控平臺zabbix
删除 console 语句引发的惨案
【C 语言】 题集 of Ⅹ
laravel构造函数和中间件执行顺序问题
应用程序和matlab的通信方式
TCP framework___ Unity
Sysom case analysis: where is the missing memory| Dragon lizard Technology
Introduction to pyGame games
Laravel service provider instance tutorial - create a service provider test instance