Tomcat Notes: URL Mapping

This is a personal study notes of Apache Tomcat. Below are main reference material.

- YouTube Apache Tomcat Full Tutorial,owed by Alpha Brains Courses. https://www.youtube.com/watch?v=rElJIPRw5iM&t=801s



  • 1、URL Mapping To Resources
    • 1.1、What we request for when hitting a URL
    • 1.2、Mapping Code
      • 1.2.1、Mapping To Resources
        • 1.2.1.1、Access Resourses in ROOT
      • 1.2.2、Mapping To Service

1、URL Mapping To Resources

1.1、What we request for when hitting a URL

When we hit a URL on browser like localhost:8080/example/hellowe are actually reqeusting a resource or service.

Resource refer to a file like .html,.image. For example when we hit example root full path which is localhost:8080/example, we are requesting index.htmland this file will be explained and rendered by browser and showed in a readable way.

I perceive those static files as a kind of resource.

But sometims we only request a service rather than a static file.

For example we click a buttton then browser sends a http request, supposing it’s URL is https://www.system.com/delete?id=1.

A Tomcat application recieve the request and provide service which is deleting a record in database.

This is requesting for a servcie.

1.2、Mapping Code

Mapping to a resource is easy. It usually is like access file system.

But mapping to a service is more tricky.

I’m going to show how Tomcatmapping URL to a resource or service.

Supposing our web application’s root URL is localhost:8080/myweb/

we have a war file like below. I omit some files for readability.

myweb.war
----index.html
----assets
--------hello.img
----WEB-INF
---------web.xml
---------classes
-------------HelloServlet.class
----META-INF

1.2.1、Mapping To Resources

As i mentioned, mapping URL to a resource basically is similar to accessing a file in file system.

For example, If we want to get index.html, just call localhost:8080/myweb/index.html.

If wanting hello.img, just call localhost:8080/myweb/assets/hello.img.

So it’s very similiar to file system.

Just notice that web root URL localhost:8080/myweb/represents hello.war’s first level subdirectory. Then you can get all static resources hierarchyly just as the same way in file system.

1.2.1.1、Access Resourses in ROOT

Tomcat can have mutiple web applications which are located under webappsfolder.

webapps
----myweb
----myweb1
----myweb2
----ROOT
---------root.txt

What I just showed is how to access static resources in myweb.

If accessig files in myweb, we should take localhost:8080/mywebas root URL.
If accessig files in myweb1, we should take localhost:8080/myweb1as root URL.

So mywebor myweb1is context which specifies which web apps you want to access.

Besides those web applicaton developed by programmer, Tomcatalways has a folder called ROOTunder webapps.

If you want to access static resources under ROOT, root.txtfor example, just remove the context and take localhost:8080/as the root URL representig the first level subdirectory of ROOT.

Thus just call localhost:8080/root.txtthen you can get root.txt.



1.2.2、Mapping To Service

Mapping URL to service could be more tricky. Because Java servlet classes usually have more deeper file structure, making URL too long.

com.org.servlet.MyServlet.java			# It has 4 levels directory in total
acme.personnel.management.MedicalPlan	# very long

For readability Tomcat has a configuration file called web.xmlto map to resources with a more simple name.

Supposing we have a servlet called DeleteRecordServletwhose doGetmethod is to delete a record in database, whose location is myweb.war/com/org/servlet/DeleteRecordServlet.java.

myweb.war			# omit some files
----com
--------org
------------servlet
----------------DeleteRecordServlet.java
----META-INF
--------web.xml
--------classes
------------com
----------------org
--------------------servlet
------------------------DeleteRecordServlet.class

Now we need to configure some mapping in web.xml, mapping a shorter url to DeleteRecordServlet.

<?xml version = "1.0" encoding = "ISO-8859-1"?>
<web-app><servlet><servlet-name>deleteServlet</servlet-name><servlet-class>com.org.servlet.DeleteRecordServlet</servlet-class></servlet><servlet-mapping><servlet-name>deleteServlet</servlet-name><url-pattern>/delete</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.html</welcome-file></welcome-file-list>
</web-app>

In this way we can hit localhost:8080/myweb/deletewhich is more simple than normal url to call DeleteRecordServlet.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/621724.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

新一代数字原住民:市场痛点与“繁”思维应对之道

随着科技的迅速发展&#xff0c;尤其是互联网的普及&#xff0c;新一代数字原住民经营者已经逐渐成为市场的主力军。不同于传统的消费者&#xff0c;有着独特的消费习惯和心理需求。企业要在这激烈的市场竞争中获得优势&#xff0c;深入了解这一群体的特征和心理、行为&#xf…

有趣的事,讲给有趣的人听

哈哈哈&#xff0c;今天不写技术了&#xff0c;今天分享一下生活&#xff0c;技术我们什么时候都可以学&#xff0c;但是生活更值得我们现在就去更好的体验&#xff01; 两年多的涤生大数据&#xff0c;认识了形形色色的小伙伴&#xff0c;陆续沟通下来6000多人&#xff0c;彼时…

数据库锁表原因、排查、解决

一.场景 场景1场景2二.原因三.排查四.解决方案 一.场景 场景1 锁表通常发生在DML&#xff08; insert 、update 、delete &#xff09; A操作进行全量数据同步&#xff0c;对整个表的粒度进行上锁&#xff0c;导致B操作只能等待A操作完成才能进入插入数据。此时就出现了锁表…

Pandas实战100例 | 案例 14: 数据透视表 - 使用 `pivot_table`

案例 14: 数据透视表 - 使用 pivot_table 知识点讲解 数据透视表是一种常见的数据汇总工具&#xff0c;用于按照一个或多个键对数据进行分类汇总。Pandas 的 pivot_table 函数提供了一种快速创建数据透视表的方法。你可以指定行索引、列索引&#xff0c;以及用于聚合的数据和…

Elasticsearch windows开箱即用【记录】

一、准备工作 安装ES之前要在本机安装好JDK&#xff0c;对应的兼容性见官网链接&#xff1a;https://www.elastic.co/cn/support/matrix ES官网链接&#xff1a;https://www.elastic.co/cn/, 我本机安装的是JDK8&#xff0c;测试使用的是7.3.0版本的ES和Kibana。 1、首先去…

Windows平台程序和Android平台程序的差异

Windows平台程序和Android平台程序的差异 1 Windows平台环境和Android平台JVM虚拟机的差异&#xff1a; 1&#xff09;由于JVM虚拟机上的数据是大端处理的&#xff0c;而Windows平台上的数据是小端的&#xff0c;所以在一些数据的处理上需要进行转换&#xff1b; 2&#xf…

vmware创建嵌套虚拟机

嵌套虚拟机的搭建 在vmware 虚拟机设置中&#xff0c;打开处理器的虚拟化Intel VT-x/EPT 或AMD-V/RVI&#xff08;v&#xff09;配置虚拟机yum 源&#xff0c;安装qemu、qemu-kvm、libvirt从阿里镜像源下载centos iso 阿里源 centos-7-x86准备虚拟机创建所需xml&#xff0c;ce…

Day32 贪心算法 part02 122. 买卖股票的最佳时机 II 55. 跳跃游戏 45. 跳跃游戏 II

贪心算法 part02 122. 买卖股票的最佳时机 II 55. 跳跃游戏 45. 跳跃游戏 II 122. 买卖股票的最佳时机 II 思路&#xff1a;计算每天的利润&#xff0c;利润如果为正&#xff0c;加到结果中去 class Solution { private:int result 0; public:int maxProfit(vector<int&g…

PyTorch项目源码学习(3)——Module类初步学习

torch.nn.Module Module类是用户使用torch来自定义网络模型的基础&#xff0c;Module的设计要求包括低耦合性&#xff0c;高模块化等等。一般来说&#xff0c;计算图上所有的子图都可以是Module的子类&#xff0c;包括卷积&#xff0c;激活函数&#xff0c;损失函数节点以及相…

完成源示例

本主题演示如何创作和使用自己的完成源类&#xff0c;类似于 .NET 的 TaskCompletionSource。 completion_source 示例的源代码 下面的列表中的代码作为示例提供。 其目的是说明如何编写自己的版本。 例如&#xff0c;支持取消和错误传播不在此示例的范围内。 #include <w…

java常见面试题:如何使用Java进行单元测试?

单元测试是软件开发中的一个重要环节&#xff0c;它确保每个单独的代码单元都能按照预期工作。以下是如何使用Java进行单元测试的详细说明&#xff1a; JUnit&#xff1a; JUnit是Java中最流行的单元测试框架。首先&#xff0c;添加JUnit依赖到你的项目中。如果你使用Maven&…

技术学习周刊第 2 期

有关 TLS/SSL 证书的一切 HTTPS 隐私安全的一些实践 关于 TLS 两篇非常好的文章&#xff0c;如果对 TLS 了解不多的话看上面两篇本章就够了。 从传统的 HTTPS 加密通信&#xff0c;到云原生架构下零信任网络所要求的 mTLS 双向认证&#xff0c;TLS 协议已经是服务通信的必备…

VR全景技术如何应用在城市发展,助力城市宣传展示

引言&#xff1a; 随着科技的不断发展&#xff0c;VR全景技术正逐渐渗透到各行各业&#xff0c;其中较为广泛的应用之一便是城市展示。那么VR全景技术如何运用在城市展示领域&#xff0c;这项技术给城市发展带来了哪些好处&#xff1f; 一. VR全景技术简介 1.什么是VR全景技术…

天梯赛 L1-094 剪切粘贴

原题链接 https://pintia.cn/problem-sets/994805046380707840/exam/problems/1649748772841508869?type7&page0 题面 &#xff08;建议点击原题链接查看&#xff0c;复制过来比较乱&#xff0c;只作预览&#xff09; 使用计算机进行文本编辑时常见的功能是剪切功能&am…

怎样制作一本旅游电子相册呢?

​随着数码技术的发展&#xff0c;旅游电子相册已成为越来越多旅游爱好者的必备工具。它不仅能让您随时随地欣赏自己的旅行回忆&#xff0c;还能分享给亲朋好友&#xff0c;甚至上传到社交媒体上&#xff0c;让更多人了解您的旅行故事。那么&#xff0c;如何制作一本精美的旅游…

Postman接口测试之断言,全网最细教程没有之一!

一、断言 在 postman 中我们是在Tests标签中编写断言&#xff0c;同时右侧封装了常用的断言&#xff0c;当然 Tests 除了可以作为断言&#xff0c;还可以当做后置处理器来编写一些后置处理代码&#xff0c;经常应用于&#xff1a; 【1】获取当前接口的响应&#xff0c;传递给…

【数据开发】BI数据报表之数据可测试性设计与分析

文章目录 1、什么是BI&数据报表2、什么是可测试性3、数据测试与方法3.1 数据准确性与对比&#xff08;重要&#xff09;3.2 数据安全性 1、什么是BI&数据报表 数据报表是一种数据可视化工具 用于将数据以图表、表格和其他可视化形式呈现出来&#xff0c;以便用户可以…

memcached简介分享

开头语&#xff1a; 大家好&#xff01;欢迎来到本篇博客&#xff0c;今天我们将深入探讨Memcached&#xff0c;这是一个高性能的分布式内存对象缓存系统。Memcached在Web开发中扮演着重要的角色&#xff0c;本文将为您介绍Memcached的基本知识、常见面试问题&#xff0c;并通…

【软件工程】基于领域建模的产品与技术方案设计(领域驱动设计DDD)

文章目录 1、领域建模2、产品方案、技术方案3、领域驱动设计DDD 1、领域建模 领域模型(domain model) 是对领域内的概念类或现实世界中对象的可视化表示。领域模型也成为概念模型、领域对象模型和分析对象模型。域模型是一种概念模型&#xff0c;也叫问题域模型。它表述的是某…