【问题标题】:JSF application giving 404 for a sub-contextJSF 应用程序为子上下文提供 404
【发布时间】:2010-09-19 05:50:46
【问题描述】:

我正在开发一个使用 JSF 的 Web 应用程序。我在“web”下有一个名为“admin”的文件夹,在“admin”文件夹下有几个 jsp 页面。我可以访问“web”下的 jsp 页面,但是当我尝试访问“admin”下的页面时,我得到“404-Requested resource cannot be found” 我的应用程序的“context.xml”是这样的:

<Context antiJARLocking="true" path="/MyApp"/>

这个东西适用于我的本地 tomcat,但是当我将它部署到我的网络托管服务提供商 tomcat 时,我遇到了上述问题。 我究竟需要做什么来解决这个问题。

这里是我在 Hosting 上的应用程序的 server.xml 提供的 tomcat:

<Host name="myapp.com" appBase="/home/myapp/public_html">
      <Alias>www.myapp.com</Alias>
      <Context path="" reloadable="true" docBase="/home/myapp/public_html" debug="1"/>
      <Context path="/manager" debug="0" privileged="true"
          docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
      </Context>
   </Host>

或者我需要将 URL-Mapping 添加到我的 web.xml 吗?

我在 web.xml 中有以下 servlet 过滤器,用于 '/admin/*' url-pattern

    <filter>
    <filter-name>SecurityFilter</filter-name>
    <filter-class>com.myapp.SecurityFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SecurityFilter</filter-name>
    <url-pattern>/admin/*</url-pattern>
</filter-mapping>

过滤代码如下:

    public void doFilter(ServletRequest request, ServletResponse response, 
                     FilterChain chain) throws IOException, ServletException {

    lgMgr.logDebug("doFilter() is called...");
    String validuser = null;
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;                        
    HttpSession session = req.getSession(true);        

    //If authorization key not in session, redirect to login page.
    validuser = (String) session.getAttribute(Common.AUTH_USER);

    if(validuser != null) {
        lgMgr.logDebug("doFilter(): User is allowed to access the page...");
        //If the user is allowed access to the URI, let the flow proceed as normal
        chain.doFilter(request, response);
        return;
    } else {
        lgMgr.logDebug("doFilter(): User is not allowed to access the page, redirecting user login...");
        //User not allowed access - redirect to login page
        res.sendRedirect(req.getContextPath() +  "/AdmLogin.jsf");
        return;
    }
}

【问题讨论】:

    标签: jsf tomcat6


    【解决方案1】:

    /WEB-INF 中的文件不可公开访问。我不知道它为什么在本地工作,但这违反了 servlet 规范。此外,JSF 不能将视图转发到 /WEB-INF 文件夹中的 JSP 页面,它们应该放在公共 webcontent 中(/WEB-INF 文件夹上方的一个文件夹)。

    【讨论】:

    • @BalusC,我尝试了你的回答,现在我的所有页面都位于“WEB”下,并且“WEB”中有“admin”文件夹,“admin”中有一些页面.我可以访问“WEB”下的页面,但不能在 WEB/admin 下访问我需要添加 servlet-mapping 或其他什么吗?
    • 不,你不需要。 web.xml 中是否有任何可能表现得很疯狂的 servlet 或过滤器或约束?另请记住,URL 中的路径/文件名区分大小写。如果文件夹名为 Admin 并且您在 URL 中使用 admin,则它将不起作用。
    • @BalusC,是的,我在 web.xml 中有以下过滤器:SecurityFiltercom.myapp.SecurityFilter类> SecurityFilter/admin/*
    • 问题的根本原因很可能在过滤器中。它显然没有正确地继续链或发送请求。尝试禁用过滤器,看看它是否有效。还添加一些日志语句打印战略利益变量并重试。
    • @BalusC,我在上面贴了过滤器代码,一切正常吗?
    猜你喜欢
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 2020-09-10
    • 2019-03-01
    • 1970-01-01
    相关资源
    最近更新 更多