【发布时间】:2013-11-10 18:29:38
【问题描述】:
Servlet
@WebServlet("/")
public class AServlet extends HttpServlet {
-- 加载.jsp 并显示“AServlet”
@WebServlet("/b")
public class BServlet extends HttpServlet {
-- 返回一个简单的 JSON
index.html
-- 显示“不是 JSP”
web.xml
...
<welcome-file-list>
<welcome-file>/</welcome-file>
</welcome-file-list>
...
每个与 servlet 不匹配的 url 都执行与 A servlet 相同的操作。
例如:
- ...localhost.../AppName/ -> 显示 AServlet - ok
- ...localhost.../AppName/loremipsum -> 显示 AServlet - 为什么不返回 404 NOT FOUND?
- ...localhost.../AppName/b -> 返回 JSON - ok
- ...localhost.../AppName/index.html -> 即使文件存在,仍然显示“AServlet”
【问题讨论】:
标签: java jsp jakarta-ee servlets web.xml