WebSphere 和 Struts2,不会欢迎文件[重复]

问题描述 投票:0回答:2

全部,

我进行了搜索和研究,但找不到将现有项目从 Tomcat 7.x 迁移到 WebSphere 8.0 所缺少的内容。我已经为这个问题创建了一个解决方法,但我的好奇心战胜了我,因为我不明白为什么。我的问题是,当我第一次将项目加载到 WebSphere 时,我得到了

There is no Action mapped for namespace [/] and action name [] associated with context path
。我研究并发现了一些可以尝试的事情。我添加了

com.ibm.ws.webcontainer.removetrailingservletpathslash=true
com.ibm.ws.webcontainer.mapFiltersToAsterisk=true
com.ibm.ws.webcontainer.invokefilterscompatibility=true

没有任何效果,最终我添加了一个空操作,重定向到欢迎页面,一切都很好。然而,我个人认为这是一种解决方法,而不是解决办法。所以,我想我的问题是为什么它不属于欢迎文件列表?我在设置/转移项目时错过了什么吗?我是否误解了过滤器的工作原理?

我在下面列出了我的 struts2 解决方法、web.xml 和文件结构。感谢你们能提供的任何帮助。

JF

web.xml 片段

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>    

<filter-mapping>
    <filter-name>securityContextFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

struts.xml 片段

编辑:如评论中所示,设置

<action name="">
解决问题

<package name="dst" extends="struts-default" namespace="/">

<!-- Added as a workaround to the problem -->
<action name="">
    <result>/index.jsp</result>
</action>
</package>

正在使用的文件结构

web
----WEB-INF
--------jsp (Folder holding jsps)
--------lib (Extra jars being used)
--------web.xml
----index.jsp

编辑

按照要求

索引.jsp

<%@ page language="java" import="java.util.*" %>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp" %> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
    </head>

    <body>
        <div> Test Page</div>       
    </body>
</html>
java struts2 websphere-8 struts-config action-mapping
2个回答
2
投票

最简单的方法是在 struts.properties 文件中将常量

struts.action.extension
设置为
action
。这样,
DefaultActionMapper
仅尝试映射
*.action
模式,将默认的空白请求
/
留给底层服务器处理。

我想你也可以重写

DefaultActionMapper
使
getMapping
方法返回
null
/
。您需要将常量
struts.mapper.class
设置为新类的限定名称。

值得一提的是,在 tomcat 中不存在同样的问题,因为 tomcat 在命中 struts 2 过滤器之前将

/
替换为欢迎文件(例如
/
变为
/index.jsp
)。


0
投票

在学习了一些 Struts2 教程后,我遇到了同样的事情,我不明白为什么它没有返回

index.jsp
下列出的
<welcome-file-list>
文件。

我发现问题出在我们的

web.xml
文件中。

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>    

<filter-mapping>
    <filter-name>securityContextFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

过滤器映射的

<url-pattern>/*</url-pattern>
表示所有请求(包括默认的空白请求)都应该过滤到struts2。这就是为什么会返回 index.jsp 文件或任何欢迎文件的原因。

如果您编辑/删除过滤器映射并再次运行,它将加载欢迎文件。

这似乎只是对过滤器如何应用于根目录的误解。

© www.soinside.com 2019 - 2024. All rights reserved.