【问题标题】:JSF: make A.jsf a default page to go to when type mydomain.comJSF:使 A.jsf 成为键入 mydomain.com 时要转到的默认页面
【发布时间】:2011-07-17 14:49:06
【问题描述】:

现在,每次我输入mydomain.com,它都会自动转到mydomain.com/projectname/home.jsf,这是我的登录页面。不知道为什么,我知道我仍在会话中,这意味着我可以导航到受限页面而无需再次登录。那么,如果我输入mydomain.com,我该怎么做,如果用户仍在会话中,我会转到mydomain.com/projectname/CentralFeed.jsf 而不是登录页面。这是我的粗略设计

在我的 web.xml 中

<welcome-file-list>
    <welcome-file>CentralFeed.jsf</welcome-file>
</welcome-file-list>          
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>jdbc-realm-scholar</realm-name>
    <form-login-config>
        <form-login-page>/home.jsf</form-login-page>
        <form-error-page>/LoginError.jsf</form-error-page>
    </form-login-config>
</login-config>
 <filter>
    <filter-name>MyFilter</filter-name>
    <filter-class>com.scholar.servlet.MyFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>MyFilter</filter-name>
    <url-pattern>/CentralFeed.jsf</url-pattern>        
    <url-pattern>/TextBook.jsf</url-pattern>
    ...
</filter-mapping> 

我不确定你们是否需要知道这一点,但我还有一个过滤器调用MyFilter,它映射到受限页面,并检查用户是否仍在会话中,如果是,那么只需 chain.doFilter(req, res);,如果然后不重定向到登录页面home.jsf

【问题讨论】:

    标签: java jsf jakarta-ee glassfish


    【解决方案1】:

    输入index.jsp

    然后放进去

    <% response.sendRedirect("desired URL"); %>
    

    删除

    <welcome-file-list>
        <welcome-file>CentralFeed.jsf</welcome-file>
    </welcome-file-list>    
    

    来自web.xml

    【讨论】:

    • 是的。通过response.sendRedirect(),您只需将客户端设置为GET 所需的URL,您想从根目录重定向
    • 我希望你不要介意我问这个,所以 CentralFeed.jsf 是我想总是先访问的页面。如果我将该页面更改为 index.jsf,我会得到与您上面建议的结果相同的结果吗?
    • 不认为它有效:这是我的例外:javax.servlet.ServletException: Error Parsing /index.xhtml: Error Traced[line: 12] The content of elements must consist of well-formed character data or markup. 我正在使用 JSF Facelets 顺便说一句
    • nvm,它必须是 .jsp 文件而不是 .xhtml
    【解决方案2】:

    &lt;welcome-file&gt; 必须指向磁盘上的物理文件,而不是一些 servlet 映射。由于您有一个 CentralFeed.xhtml 文件,因此 &lt;welcome-file&gt;CentralFeed.jsf 将无法正常工作。

    有两种解决方案(除了 Jigar 建议的 scriptlet hack):

    1. CentralFeed.xhtml 旁边创建一个空文件CentralFeed.jsf 文件。这会使服务器误以为文件实际存在。

    2. FacesServlet 映射到*.xhtml 而不是*.jsf。虽然这在 JSF 1.x 中是不可能的,因为它会在无限循环中运行,但这在 JSF 2.0 上运行良好。您的问题历史确认您使用的是 JSF 2.0。这样,您只需将&lt;welcome-file&gt; 设置为CentralFeed.xhtml

    【讨论】:

    • 非常感谢您提供的重要信息。学习新东西:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2013-02-03
    • 2015-02-19
    相关资源
    最近更新 更多