Servlets getRequestDispatcher(.).forward(req,res)抛出java.io.FileNotFoundException

Servlets getRequestDispatcher(.).forward(req,res)抛出java.io.FileNotFoundException,servlets,websphere-8,requestdispatcher,Servlets,Websphere 8,Requestdispatcher,我已经将Servlet从2.4升级到3.0,并在WebSphere8.5.5.8上部署了我的应用程序。应用服务器正常启动。 当我试图在浏览器中访问我的home.jsp页面时,它会抛出: 控制器主错误OG1000SRVE0190E:未找到文件:/servlet/com.platform7.affina.operations.servlet.ValidateLoginUser 当我尝试调试时,代码会命中我的主控制器Servlet(在同一个包中),但在我调用的控制器Servlet类中: this.ge

我已经将Servlet从2.4升级到3.0,并在WebSphere8.5.5.8上部署了我的应用程序。应用服务器正常启动。 当我试图在浏览器中访问我的
home.jsp
页面时,它会抛出:

控制器主错误OG1000SRVE0190E:未找到文件:/servlet/com.platform7.affina.operations.servlet.ValidateLoginUser

当我尝试调试时,代码会命中我的主控制器Servlet(在同一个包中),但在我调用的控制器Servlet类中:

this.getServletContext().getRequestDispatcher("Servlet/com.platform7.affina.operations.servlet.ValidateLoginUser").forward(request, response);
它抛出:

Servlet/com.platform7.affina.operations.Servlet.ValidateLoginUser的FileNotFoundException

但是
ValidateLoginUser
位于相同的包和类文件夹位置

文件夹结构:

\NEED4SPEEDCell02\operations_1.ear\OperationsWeb.war\WEB-INF\classes\com\platform7\affina\operations\servlet
ControllerMain.class
ValidateLoginUser.class
在同一个servlet包中

我的
Web.xml
文件:


servletMain
com.platform7.affina.operations.servlet.ControllerMain
1.
servletMain
/控制员
因此,当我访问我的URL时:它点击
ControllerMain.class
,但在这个类中,我调用的是另一个servlet,它不是
web.xml
的一部分,而是位于
ControllerMain.class
的同一个包中

打印realpath时:
this.getServletContext().getRealPath(“/”)

我得到:

C:\WebSphere858\AppServer\profiles\AppSrv01\installedApps\NEED4SPEEDCell02\operations\u 1.ear\OperationsWeb.war

我也尝试过使用
getNamedDispatcher(..)
但是抛出:
null


相同的代码在Websphere 7上运行良好,甚至在Websphere 8.5.5.5上运行良好

您似乎依赖于传统的
InvokerServlet
,已知它存在严重的安全漏洞。这在Tomcat5和克隆(WebSphere4)中被弃用,在Tomcat7和克隆(WebSphere6)中被删除

你不应该再使用它了。只需将servlet映射到普通URL模式并调用它。假设servlet通过servlet类上的
@WebServlet(“/validateLoginUser”)
注释,或通过servlet上的
/validateLoginUser
映射,映射到
/validateLoginUser
的URL模式上,那么您可以在其上获得请求分派器,如下所示:

request.getRequestDispatcher("/validateLoginUser");
或者,只需使用一个方法将共享代码重构为一个普通的Java类,并以通常的Java方式调用它。现在在servlet中紧密耦合共享验证逻辑有点奇怪

另见:
    • 由于
      com.ibm.ws.webcontainer.disallowServeServletsByClassname
      属性的默认设置已更改

      请注意:此APAR已更改 WebContainer自定义属性
      com.ibm.ws.webcontainer.disallowServeServletsByClassname
      false正确这样就不会发生安全威胁。在此更改之前 由开发人员记住将自定义属性更改为 在部署到生产环境之前为true

      物业名称: com.ibm.ws.webcontainer.disallowServeServletsByClassname说明: 如果设置为true,则不允许使用serveServletsByClassnameEnabled 在应用程序服务器级别,重写 ServeServletsByclassName在应用程序级别启用。这 属性影响所有应用程序。值:真(默认)/假

      您需要将该自定义属性添加到Web容器中,并将其设置为false,以便按类名为servlet提供服务

      但是正如BalusC所建议的,您应该以以下形式将servlet添加到
      web.xml

      <servlet>
          <servlet-name>servletMain</servlet-name>
          <servlet-class>com.platform7.affina.operations.servlet.ValidateLoginUser</servlet-class>
          <load-on-startup>1</load-on-startup>
      </servlet>
      
      <servlet-mapping>
          <servlet-name>servletMain</servlet-name>
          <url-pattern>/validateLoginUser</url-pattern>
      </servlet-mapping>
      

      并对同一软件包中的其他类执行相同的操作。

      为了使上述升级工作正常,我做了以下几项更改,以供将来参考

      主要是,我必须更改websphere的绑定文件。 以前,我有两个绑定ibmwebbnd.xmiibm-web-ext.xmi

      ibm-web-bnd.xmi


      希望这能有所帮助。

      谢谢你对巴卢斯的帮助。问题是,我的公司不想做重大的代码更改。否则,我将最好删除web.xml的所有这些旧代码遗留模式,删除紧密耦合,并继续使用注释。我们需要支持WebSphere8.5.5.8,它需要Servlet3。原始代码是使用Servlet 2.4返回的。同样的代码适用于Websphere 7,甚至适用于Websphere 8.5.5.5,但它开始抱怨8.5.5.8:(谢谢BalusC,你是对的,你的解决方案也很有效。Brilliant Gas,很抱歉在你建议的更改后延迟回复,因为它花费了很多部署时间。所以在评论之前考虑先尝试一下。非常感谢你的解决方案。它结合了你的解决方案和BalusC。我必须更改我所有的servlet调用patt。)ern getServletContext().getRequestDispatcher(“…”)和web.xml。再次非常感谢。很高兴为您加热。如果您将servlet添加到
      web.xml
      ,并将dispatcher更改为使用映射名称,则您不再需要设置该属性,也不需要在
      ibm-web-ext.xml
      中设置
      serveServletsByClassnameEnabled
      this.getServletContext().getRequestDispatcher("/validateLoginUser").forward(request, response);
      
      <?xml version="1.0" encoding="UTF-8"?>
      <com.ibm.ejs.models.base.bindings.webappbnd:WebAppBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:com.ibm.ejs.models.base.bindings.webappbnd="webappbnd.xmi" xmi:id="WebAppBinding_1226331113121" virtualHostName="default_host">
        <webapp href="WEB-INF/web.xml#WebApp"/>
          <resRefBindings xmi:id="ResourceRefBinding_1226331113121" jndiName="AffinaDataSource_pma">
            <bindingResourceRef href="WEB-INF/web.xml#ResourceRef_AffinaDataSource_pma"/>
          </resRefBindings>
      </com.ibm.ejs.models.base.bindings.webappbnd:WebAppBinding>
      
      <?xml version="1.0" encoding="UTF-8"?>
      <com.ibm.ejs.models.base.extensions.webappext:WebAppExtension 
          xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" 
          xmlns:com.ibm.ejs.models.base.extensions.webappext="webappext.xmi" 
          xmi:id="WebAppExtension_1226331113121"
          serveServletsByClassnameEnabled="true">
        <webApp href="WEB-INF/web.xml#WebApp"/>
        <jspAttributes xmi:id="JSPAttribute_1226331113121" name="reloadEnabled" value="true"/>
        <jspAttributes xmi:id="JSPAttribute_1226331113122" name="reloadInterval" value="10"/>
      </com.ibm.ejs.models.base.extensions.webappext:WebAppExtension>
      
      <?xml version="1.0" encoding="UTF-8"?>
      <web-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd" version="1.0">
      
        <virtual-host name="default_host"/>
        <resource-ref name="AffinaDataSourceAlias_pma" binding-name="AffinaDataSource_pma"/>
      
      </web-bnd>
      
      set PERFJAVAOPTION=-Xms256m -Xmx512m -Xquickstart