Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading Struts to 2.5.31 from 2.3 and jquery from 3.7.1 to 4.0.3 - Mapping no longer working #348

Open
nsethblanchard opened this issue Sep 22, 2023 · 5 comments

Comments

@nsethblanchard
Copy link

nsethblanchard commented Sep 22, 2023

Hey all! I am struggling to find the issue for why my page isn't loading correctly during the process of upgrading my dependencies. I feel like I have tried everything so am going to include more code than is probably necessary. I added jquery-ui based on some other discussions I read but that didn't seem to help.

From my parent pom.xml file.

<struts.version>2.5.31</struts.version>
 <struts.jquery.version>4.0.3</struts.jquery.version>
 <struts.jquery-ui.version>1.13.0</struts.jquery-ui.version>

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>${struts.version}</version>
</dependency>
 <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-json-plugin</artifactId>
    <version>${struts.version}</version>
 </dependency>
 <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-tiles-plugin</artifactId>
    <version>${struts.version}</version>
  </dependency>
  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-plugin</artifactId>
    <version>${struts.jquery.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-velocity-plugin</artifactId>
        </exclusion>
    </exclusions>
  </dependency>
  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jqueFn</artifactId>
    <version>${struts.jquery.version}</version>
  </dependency>
  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-chart-plugin</artifactId>
    <version>${struts.jquery.version}</version>
  </dependency>
  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-grid-plugin</artifactId>
    <version>${struts.jquery.version}</version>
  </dependency>
  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-richtext-plugin</artifactId>
    <version>${struts.jquery.version}</version>
  </dependency>
  <dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery-ui</artifactId>
    <version>${struts.jquery-ui.version}</version>
  </dependency>

From my index.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>

<s:url var="getMainPage" action="settings_main.action"/>
<s:url var="getCurrentStatus" action="controller_main.action" />
<s:url var="getSideMenu" action="admin_getSideMenuDB.action" />

...and then within the body (and this all worked before attempting to upgrade)

   <div id="page_body">
            <table style="width:100%;padding:0;margin:0;border-spacing:0;">
                <tr>
                    <td style="background-color:#00205c;width:100px;vertical-align:top;padding:0;margin:0;">
                        <sj:div id="sideMenuDiv" href="%{getSideMenu}"/>
                    </td>
                    <td rowspan="2" style="padding:0;margin:0;background-color:#fff;vertical-align:top;">
                        <div style="height:5px;margin:0 0 5px 10px;">
                            <span id="indicator" style="display:block;"><img src="<s:url value="/images/indicator.gif" />"  alt=""/>
                                <s:property value="getText('page.label.pleaseWait')" />
                            </span>
                        </div>
                        <div id="contentDiv" style="padding:0;margin:0;overflow-y:auto;overflow-x:hidden;">
                            <sj:div id="content_window" href="%{getMainPage}" indicator="indicator"/>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="background-color:#00205c;"><img src="images/transparent.gif" width="100" alt=""/>
                    </td>
                </tr>
            </table>
        </div>

None of the top struts url pages have changed at all.

Not sure if this adds anything because it also wasn't changed but I read that wildcard action mapping may have changed but this is in my struts.xml file.

<action name="settings_*" class="com.removed.action.SettingsAction" method="{1}">
  <result name="input">/pages/settings.jsp</result>
  <result>/pages/settings.jsp</result>
  <result name="main">/pages/mainMenu.jsp</result>
</action>

This all works if I revert my version updates but gives me a 404 now. Any ideas or follow up questions so I can clarify?

@lukaszlenart
Copy link
Member

Do you get any JS errors? Also do you need all these?

  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jqueFn</artifactId>
    <version>${struts.jquery.version}</version>
  </dependency>
  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-chart-plugin</artifactId>
    <version>${struts.jquery.version}</version>
  </dependency>
  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-grid-plugin</artifactId>
    <version>${struts.jquery.version}</version>
  </dependency>
  <dependency>
    <groupId>com.jgeppert.struts2.jquery</groupId>
    <artifactId>struts2-jquery-richtext-plugin</artifactId>
    <version>${struts.jquery.version}</version>
  </dependency>
  <dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery-ui</artifactId>
    <version>${struts.jquery-ui.version}</version>
  </dependency>

if not I would remove them

@iamcessssy
Copy link

iamcessssy commented Oct 17, 2023

Wildcard Action Mapping no longer works after updating to Struts 2.5.
It is Strict Method Invocation and since Struts 2.5 it is enabled by default.
From the docs about SMI and wildcard mappings:

When using wildcard mapping in actions' definitions SMI works in two ways:

SMI is disabled - any wildcard will be substituted with the default RegEx, ie.: will be translated into allowedMethod = "regex:perform([A-Za-z0-9_$]*)".
SMI is enabled - no wildcard substitution will happen, you must strictly define which methods can be accessed by annotations or tag.

So, one of the solutions that worked is to disabled it per package
like this:
<package name="home" extends="app-default" namespace="/sample" strict-method-invocation="false"> <action name="settings_*" class="com.removed.action.SettingsAction" method="{1}"> ... </action> </package>
``

@nsethblanchard
Copy link
Author

@lukaszlenart, I will check if I absolutely need all of those dependencies because you are right, there are a lot of seemingly associated ones. Trying not to damage any of this old code :-). I wasn't getting any JS errors, I don't believe. @iamcessssy, I had seen wildcard wasn't able to be used by default and am pretty sure that I tried to set the strict method invocation to false across the board, but maybe adding to each individual one would help. Thanks for the idea!

@lukaszlenart
Copy link
Member

lukaszlenart commented Oct 22, 2023

@nsethblanchard SMI is enabled by default and you can only disable it per package

you have option to disable it per package - there is no global switch to disable SMI for the whole application.

https://struts.apache.org/core-developers/action-configuration#strict-method-invocation

@sab-imad
Copy link

sab-imad commented Jul 15, 2024

@nsethblanchard is it necessary to add

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery-ui</artifactId>
    <version>${struts.jquery-ui.version}</version>
  </dependency>

with struts2-jquery-plugin and struts2-jquery-tree-plugin?

because I am facing issue with classic theme, and custom jstree images/icons are not populating in UI. though if I add background-size =80%; manually in the browser then the images will show but when I try with JS function its not working.

will you be able to guide me on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants