自定义 Servlet 过滤器的 Weblogic 10.3.6 问题
Weblogic 10.3.6 Issue with Custom Servlet Filters
我正在使用 struts-hibernate 项目并成功部署在多个 Web 应用程序服务器中,例如 Tomcat、JBoss、WAS 等
这是我在 WebLogic 10.3.6 服务器中部署相同应用程序时遇到的一些奇怪问题。
我在 web.xml 中有几个过滤器用于在操作 类 之前处理请求。这些过滤器在应用程序加载时初始化(调试进入 init 方法),当我点击 URL 时,它应该首先进入我的过滤器的 doFilter 方法 类,但在 weblogic 的情况下它不起作用。
在其他 Web 应用程序服务器中同样适用。
Web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Parameter for JSTL resource bundle usage. -->
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>app_resources</param-value>
</context-param>
<!-- Parameters related to application configuration. -->
<context-param>
<param-name>configFile</param-name>
<param-value>/WEB-INF/app-config.xml</param-value>
</context-param>
<context-param>
<param-name>configClass</param-name>
<param-value>org.apache.struts.apps.ajaxchat.AjaxChatConfig</param-value>
</context-param>
<filter>
<filter-name>
Logging Filter
</filter-name>
<description>
Filter used to log each user action
</description>
<filter-class>
com.mypackage.ActivityLoggingFilter
</filter-class>
</filter>
<!-- Use this if you want db authentication -->
<filter>
<filter-name>
AuthFilter
</filter-name>
<description>
Filter handling custom user authentication
</description>
<filter-class>
com.mypackage.AuthenticationFilter
</filter-class>
<init-param>
<param-name>auth_uri</param-name>
<param-value>/Login.do</param-value>
</init-param>
<init-param>
<param-name>password_change_uri</param-name>
<param-value>/PasChangeExp.do</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<servlet-name>tcode</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<servlet-name>help</servlet-name>
</filter-mapping>
<!-- Map the filter to a Servlet or URL -->
<filter-mapping>
<filter-name>Logging Filter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
<!-- Listeners -->
<!--
<listener>
<listener-class>com.mypackage.HibernateListener</listener-class>
</listener>
-->
<listener>
<listener-class>
com.mypackage.SessionListener
</listener-class>
</listener>
<listener>
<listener-class>com.mypackage.ContextListener</listener-class>
</listener>
<listener>
<listener-class>javawebparts.listener.AppConfigContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Log4JInitServlet</servlet-name>
<servlet-class>com.mypackage.Log4JInitServlet</servlet-class>
<init-param>
<param-name>log4j-properties-location</param-name>
<param-value>/WEB-INF/classes/logging.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.mypackage.InheritanceActionServet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/modules/main/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/main/user</param-name>
<param-value>/WEB-INF/modules/main/modules/user/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/main/group</param-name>
<param-value>/WEB-INF/modules/main/modules/group/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/main/profile</param-name>
<param-value>/WEB-INF/modules/main/modules/profile/config/struts-config.xml</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet>
<servlet-name>MenuInitServlet</servlet-name>
<servlet-class>com.mypackage.MenuInitServlet</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
<servlet>
<servlet-name>JnlpDownloadServlet</servlet-name>
<servlet-class>com.sun.javaws.servlet.JnlpDownloadServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>tcode</servlet-name>
<servlet-class>com.mypackage.TcodeServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>help</servlet-name>
<servlet-class>com.mypackage.HelpServlet</servlet-class>
</servlet>
<!-- servlet-mapping>
<servlet-name>JnlpDownloadServlet</servlet-name>
<url-pattern>*.jnlp</url-pattern>
</servlet-mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tcode</servlet-name>
<url-pattern>/tcode/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>help</servlet-name>
<url-pattern>/static/help/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>400</error-code>
<location>/ErrorPage.do</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/ErrorPage404.do</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/ErrorPage500.do</location>
</error-page>
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/menu</taglib-uri>
<taglib-location>/WEB-INF/tlds/menu.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/navigator</taglib-uri>
<taglib-location>/WEB-INF/tlds/navigator.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/list</taglib-uri>
<taglib-location>/WEB-INF/tlds/list.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/table</taglib-uri>
<taglib-location>/WEB-INF/tlds/table.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/monitor</taglib-uri>
<taglib-location>/WEB-INF/tlds/client.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/alerts</taglib-uri>
<taglib-location>/WEB-INF/tlds/alerts.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/custom</taglib-uri>
<taglib-location>/WEB-INF/tlds/customFields.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/filter</taglib-uri>
<taglib-location>/WEB-INF/tlds/filter.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/selectChoices</taglib-uri>
<taglib-location>/WEB-INF/tlds/selectChoices.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/matrix</taglib-uri>
<taglib-location>/WEB-INF/tlds/matrix.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/report</taglib-uri>
<taglib-location>/WEB-INF/tlds/report.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/listWithActionTag</taglib-uri>
<taglib-location>/WEB-INF/tlds/listWithActionTag.tld</taglib-location>
</taglib>
<!-- resource -->
<!--resource-ref>
<res-ref-name>jdbc/prototype</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref-->
</web-app>
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<context-root>mps</context-root>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>
我发现在扩展Filter class时,需要在filter class方法上面添加@Override注解。添加这个解决了我的问题。
我正在使用 struts-hibernate 项目并成功部署在多个 Web 应用程序服务器中,例如 Tomcat、JBoss、WAS 等
这是我在 WebLogic 10.3.6 服务器中部署相同应用程序时遇到的一些奇怪问题。
我在 web.xml 中有几个过滤器用于在操作 类 之前处理请求。这些过滤器在应用程序加载时初始化(调试进入 init 方法),当我点击 URL 时,它应该首先进入我的过滤器的 doFilter 方法 类,但在 weblogic 的情况下它不起作用。
在其他 Web 应用程序服务器中同样适用。
Web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Parameter for JSTL resource bundle usage. -->
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>app_resources</param-value>
</context-param>
<!-- Parameters related to application configuration. -->
<context-param>
<param-name>configFile</param-name>
<param-value>/WEB-INF/app-config.xml</param-value>
</context-param>
<context-param>
<param-name>configClass</param-name>
<param-value>org.apache.struts.apps.ajaxchat.AjaxChatConfig</param-value>
</context-param>
<filter>
<filter-name>
Logging Filter
</filter-name>
<description>
Filter used to log each user action
</description>
<filter-class>
com.mypackage.ActivityLoggingFilter
</filter-class>
</filter>
<!-- Use this if you want db authentication -->
<filter>
<filter-name>
AuthFilter
</filter-name>
<description>
Filter handling custom user authentication
</description>
<filter-class>
com.mypackage.AuthenticationFilter
</filter-class>
<init-param>
<param-name>auth_uri</param-name>
<param-value>/Login.do</param-value>
</init-param>
<init-param>
<param-name>password_change_uri</param-name>
<param-value>/PasChangeExp.do</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<servlet-name>tcode</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>AuthFilter</filter-name>
<servlet-name>help</servlet-name>
</filter-mapping>
<!-- Map the filter to a Servlet or URL -->
<filter-mapping>
<filter-name>Logging Filter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
<!-- Listeners -->
<!--
<listener>
<listener-class>com.mypackage.HibernateListener</listener-class>
</listener>
-->
<listener>
<listener-class>
com.mypackage.SessionListener
</listener-class>
</listener>
<listener>
<listener-class>com.mypackage.ContextListener</listener-class>
</listener>
<listener>
<listener-class>javawebparts.listener.AppConfigContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Log4JInitServlet</servlet-name>
<servlet-class>com.mypackage.Log4JInitServlet</servlet-class>
<init-param>
<param-name>log4j-properties-location</param-name>
<param-value>/WEB-INF/classes/logging.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>com.mypackage.InheritanceActionServet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/modules/main/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/main/user</param-name>
<param-value>/WEB-INF/modules/main/modules/user/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/main/group</param-name>
<param-value>/WEB-INF/modules/main/modules/group/config/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/main/profile</param-name>
<param-value>/WEB-INF/modules/main/modules/profile/config/struts-config.xml</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet>
<servlet-name>MenuInitServlet</servlet-name>
<servlet-class>com.mypackage.MenuInitServlet</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
<servlet>
<servlet-name>JnlpDownloadServlet</servlet-name>
<servlet-class>com.sun.javaws.servlet.JnlpDownloadServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>tcode</servlet-name>
<servlet-class>com.mypackage.TcodeServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>help</servlet-name>
<servlet-class>com.mypackage.HelpServlet</servlet-class>
</servlet>
<!-- servlet-mapping>
<servlet-name>JnlpDownloadServlet</servlet-name>
<url-pattern>*.jnlp</url-pattern>
</servlet-mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>tcode</servlet-name>
<url-pattern>/tcode/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>help</servlet-name>
<url-pattern>/static/help/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>400</error-code>
<location>/ErrorPage.do</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/ErrorPage404.do</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/ErrorPage500.do</location>
</error-page>
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/menu</taglib-uri>
<taglib-location>/WEB-INF/tlds/menu.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/navigator</taglib-uri>
<taglib-location>/WEB-INF/tlds/navigator.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/list</taglib-uri>
<taglib-location>/WEB-INF/tlds/list.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/table</taglib-uri>
<taglib-location>/WEB-INF/tlds/table.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/monitor</taglib-uri>
<taglib-location>/WEB-INF/tlds/client.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/alerts</taglib-uri>
<taglib-location>/WEB-INF/tlds/alerts.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/custom</taglib-uri>
<taglib-location>/WEB-INF/tlds/customFields.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/filter</taglib-uri>
<taglib-location>/WEB-INF/tlds/filter.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/selectChoices</taglib-uri>
<taglib-location>/WEB-INF/tlds/selectChoices.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/matrix</taglib-uri>
<taglib-location>/WEB-INF/tlds/matrix.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/report</taglib-uri>
<taglib-location>/WEB-INF/tlds/report.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/listWithActionTag</taglib-uri>
<taglib-location>/WEB-INF/tlds/listWithActionTag.tld</taglib-location>
</taglib>
<!-- resource -->
<!--resource-ref>
<res-ref-name>jdbc/prototype</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref-->
</web-app>
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
<context-root>mps</context-root>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
<show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>
</weblogic-web-app>
我发现在扩展Filter class时,需要在filter class方法上面添加@Override注解。添加这个解决了我的问题。