【问题标题】:How am I supposed to add a JSP file to my application?我应该如何将 JSP 文件添加到我的应用程序?
【发布时间】:2012-05-04 17:37:28
【问题描述】:

我创建了一个名为loggedOut.jsp 的新JSP 文件,在我的应用程序中单击注销后,我希望被定向到该文件。虽然我被带到登录页面,但没有转到loggedOut.jsp文件,但url显示为转到loggedOut.jsp。

我正在使用 tomcat 7 和 vaadin。

如何让我的应用程序将我带到loggedOut.jsp?

我的 web.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Messages</display-name>
<context-param>
    <description>
    Vaadin production mode</description>
    <param-name>productionMode</p+aram-name>
    <param-value>false</param-value>
</context-param>
<servlet>
    <servlet-name>MessagesApplication</servlet-name>
    <servlet-class>org.vaadin.artur.icepush.ICEPushServlet</servlet-class>
    <init-param>
        <description>
        Vaadin application class to start</description>
        <param-name>application</param-name>
        <param-value>com.entropix.msgapp.main.MsgApplication</param-value>
    </init-param>
    <init-param>
        <description>
        Application widgetset</description>
        <param-name>widgetset</param-name>
        <param-value>com.entropix.msgapp.main.widgetset.MessagesWidgetset</param-value>
    </init-param>
</servlet>
<session-config>
    <session-timeout>30</session-timeout>
</session-config>
<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>/login.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>/loginFailed.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>/loggedOut.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>MessagesApplication</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <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>
<security-constraint>
    <display-name>LoginConstraint</display-name>
    <web-resource-collection>
        <web-resource-name>MessagesUser</web-resource-name>
        <description>Messages Application Authenticated User</description>
        <url-pattern>/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>messages-user</role-name>
    </auth-constraint>
    <user-data-constraint>
        <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<security-role>
    <description>Messages User</description>
    <role-name>messages-user</role-name>
</security-role>
<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.jsp</form-login-page>
        <form-error-page>/loginFailed.jsp</form-error-page>
        </form-login-config>
</login-config>

【问题讨论】:

  • 为了获得更好的帮助,请发布您到目前为止所做的任何事情。

标签: java jsp tomcat vaadin


【解决方案1】:

如果用户未通过身份验证,您可能已将 webapp(或 webapp 中的过滤器)配置为重定向到所有(或大量)“受保护” URL 的登录页面。

确保loggedOut.jsp 不是那些需要经过身份验证才能访问的“受保护”URL(或URL 模式)的一部分。这通常在 web.xml 文件中配置,但您是唯一知道您的应用如何工作的人。

编辑:现在您已经向我们展示了 web.xml 文件,请查看其中的内容。您正在使用 url 模式 /*(这意味着 webapp 的每个 URL)定义一个资源集合,它需要在角色 messages-user 中才能被访问。这意味着要访问 webapp 的每个 URL,您必须经过身份验证并通过此身份验证获得 messages-user 角色。因此,一旦您注销,您就将用户重定向到 logedOut.jsp。但是由于URL需要经过认证才能访问,所以会显示登录页面。

这里有一个教程给你:http://docs.oracle.com/javaee/5/tutorial/doc/bncas.html

【讨论】:

  • 在哪里可以找到“受保护”的网址?
  • 如我所说:“这通常是在web.xml文件中配置的”。
  • 对不起,应该更具体。我对此很陌生,并且不确定要寻找这些受保护的网址。我将它添加到我的 web.xml 中,就像我已经为 login.jsp 所做的一样。我没有看到任何其他地方不允许我导航到它。 servlet-mapping> jsp/loggedOut.jsp
  • 不需要添加到 web.xml 中。这只是不必要的噪音。您为什么不编辑您的问题并向我们展示 web.xml 文件?既然您正在处理 JEE webapp 中的身份验证,为什么不阅读有关它的规范或至少教程?尝试随机解决方案并不是最好的策略。
  • 我一直在尝试找到一些关于这样做的教程,但没有成功。我现在发布了我的 web.xml。
猜你喜欢
  • 2010-09-05
  • 2016-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-03
  • 1970-01-01
相关资源
最近更新 更多