【问题标题】:Why is every url "redirecting" to the welcome-file url?为什么每个网址都“重定向”到欢迎文件网址?
【发布时间】: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


    【解决方案1】:

    将 Servlet 映射到“/”使其成为默认 Servlet,这意味着它将处理与任何其他映射不匹配的所有请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 2015-08-02
      • 2021-06-22
      相关资源
      最近更新 更多