【问题标题】:web.xml page can't find home welcome-fileweb.xml 页面找不到主页欢迎文件
【发布时间】:2019-03-28 07:11:33
【问题描述】:

Ecpise 对我说我在 web.xml 页面中有一个错误,但我找不到它。 这是 web.xml 页面

  <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0">
    <display-name>UnogasApp</display-name>
    <filter-mapping>
       <filter-name>jdbcFilter</filter-name>
       <url-pattern>/*</url-pattern>
   </filter-mapping>

   <filter-mapping>
       <filter-name>cookieFilter</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>
     <welcome-file-list>
     <welcome-file>home</welcome-file>
     <welcome-file>index.html</welcome-file>
     <welcome-file>index.htm</welcome-file>
     <welcome-file>index.jsp</welcome-file>
     <welcome-file>default.html</welcome-file>
     <welcome-file>default.htm</welcome-file>
     <welcome-file>default.jsp</welcome-file>
     </welcome-file-list>
     </web-app>

当我尝试运行代码时,出现以下错误: HTTP 状态 404 – 未找到 WEB-INF/views/homeView.jsp 源服务器没有找到目标资源的当前表示或不愿意透露存在的表示。 我认为是因为 servlet 在欢迎文件中找不到主字符串。 谢谢

我添加了 servlet 类

@WebServlet(urlPatterns = { "/home"})
public class HomeServlet extends HttpServlet {
   private static final long serialVersionUID = 1L;

   public HomeServlet() {
       super();
   }

   @Override
   protected void doGet(HttpServletRequest request, HttpServletResponse response)
           throws ServletException, IOException {


       // Forward to /WEB-INF/views/homeView.jsp
       // (Users can not access directly into JSP pages placed in WEB-INF)
       RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/homeView.jsp");

       dispatcher.forward(request, response);

   }

   @Override
   protected void doPost(HttpServletRequest request, HttpServletResponse response)
           throws ServletException, IOException {
       doGet(request, response);
   }

}

【问题讨论】:

  • 您的 WEB-INF 文件夹中的 jsp 文件无法直接访问。这就是为什么。移动到您的根文件夹
  • 谢谢,但现在它给了我错误类型状态报告消息 /UnogasApp/ 描述源服务器没有找到目标资源的当前表示或不愿意透露存在的表示。
  • 部署描述符中还有一个错误:带有“X”的错误页面。
  • 现在可以了,谢谢@JonathanLaliberte

标签: servlets web.xml


【解决方案1】:

您的 WEB-INF 文件夹中的 jsp 文件无法直接访问。这就是为什么。移动到您的根文件夹 -

【讨论】:

    猜你喜欢
    • 2012-09-04
    • 2010-12-26
    • 2018-01-24
    • 1970-01-01
    • 2019-10-19
    • 2014-02-14
    • 2020-07-23
    • 2019-11-13
    • 2015-07-10
    相关资源
    最近更新 更多