WebSphere & Struts2, not going to welcome file [duplicate]
Asked Answered
D

2

0

All,

I have searched and researched and I cannot find what I am missing for migrating a existing project from Tomcat 7.x to WebSphere 8.0. I have created a work around for the problem but my curiosity is getting the better of me because I don't understand the why. My problem is that when I first loaded the project to WebSphere I was getting There is no Action mapped for namespace [/] and action name [] associated with context path. I researched and found a couple of things to try. I added

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

with no avail and ultimately I added an empty action that redirected to the welcome page and all was well. However, I personally view this as a work-around and not a fix. So, I guess my question is why does it not fall through to the welcome file list? Have I missed something in setting up/transferring the project? Am I misunderstanding how filters work?

I've included below my struts2 workaround, web.xml and the file structure. Thanks for anything you guys can help with.

JF

web.xml Snippit

<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 snippit

EDIT: as in the comment, set <action name=""> solve the question

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

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

File Structure being used

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

EDIT

As per request

Index.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>
Decorum answered 14/5, 2015 at 15:19 Comment(10)
Show your index.jsp content.Maldon
You should redirect from index.jsp to some action.Maldon
Right, and we do but I was testing to see where the break was so I removed the redirect and left the above page. My understanding was that it should display the page?Decorum
So then the redirect aside, any ideas on what am I missing that is preventing it from showing this page?Decorum
So you are saying that w/o redirection in index.jsp and w/o <action name=""> it displays same error?Maldon
Yes, so if I have it configured with or without redirection and w/o <action name=""> then I get the no Action mapped error. The moment i add the <action name=""> tag then the error goes away. However, I was under the impression that the <welcome-file> should kick in when I access it like http://localhost:9080/cars/ Where the webcontext is /cars/Decorum
Have you explicitly set a webcontext to /cars/? If yes try without trailing slash /cars.Maldon
As recommended I removed the trailing slash and received the same error.Decorum
The web server can add the slash if the path used for a directory. Some servers think that they better use prettifying urls over the row ones by adding a slash to the end. The convention plugin can be used to handle action when a slash is absent by adding it explicitly. See this answer.Wellspring
So providing I understood all of that correctly that means I should be careful with my naming to ensure I don't have a folder named cars so it knows that it's not an action right?Decorum
F
2

The easiest approach is to set the constant struts.action.extension to action in struts.properties file. In this way, the DefaultActionMapper only attempts to map *.action pattern, leaving the default blank request / to be handled by the underlying server.

I guess that you could also override the DefaultActionMapper to make getMapping method to return null for /. You would need to set the constant struts.mapper.class to the qualified name of the new class.

It's worth mentioning that the same problem doesn't exist in tomcat because tomcat replaces / with the welcome file (e.g. / becomes /index.jsp) before hitting the struts 2 filters.

Fairley answered 6/11, 2017 at 9:27 Comment(0)
C
0

I ran into the same thing after following some Struts2 Tutorials, I couldn't figure out why it wasn't returning the index.jsp file that was listed under <welcome-file-list>.

I figured out the problem is in our web.xml file.

<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>

The filter-mapping's <url-pattern>/*</url-pattern> is saying that all requests including the default blank request should be filtered to struts2. Which is why the index.jsp file or any of the welcome-files are ever returned.

If you edit/delete the filter-mapping and run again, it will load the welcome files.

It seems it was just a misunderstanding of how the filter would apply to the root directory.

Cayser answered 5/12, 2016 at 22:1 Comment(3)
If you remove filter mapping then S2 won't work.Maldon
@AleksandrM You're right, removing the filter would be removing S2, I wasn't suggesting he remove the filter. I'mt pointing out how to get the welcome-files to work as he expected by removing the filter.Cayser
The welcome file configuration works with filters.Maldon

© 2022 - 2024 — McMap. All rights reserved.