Strts2 dynamic methods and issues used between versions

1.An error occurred when Struts2 used the dynamic method Universal Functional Test (Version 2.5).I thought I made a mistake, but I went back and checked for it, and then I used the (version 2.3) test.No errors were found in version 2.3.After the official website query, default.properties default configuration in version 2.5, as shown in the figure

2. Turn on dynamic generic configuration, default is false

3. This then requires that we add the configuration in struts.xml

<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

4. Take the test with great care, and the result is not predicted, but comes with the same error as the original.Figure

5. Why do I make so many mistakes?How many lines do you make a mistake?Reason added in struts.xml

<! -- Enable Development Mode Configuration -->
<constant name="struts.devMode" value="true"></constant>

6. To get back to the point, the headache remains unresolved.There was no way but to consult the bride.

As expected, Du Niang was still there. I found it

 http://www.cnblogs.com/gsy52300/p/5778754.html

After I saw it, I was finally in a better mood and had a magical headache.But I find this is not the result I ultimately want.

Configuration after summarizing it

   The struts.xml configuration is as follows

<struts>
   <!-- Using this method, dynamic wildcards can be turned off here -->
   <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
   <!-- Enable development mode -->
   <constant name="struts.devMode" value="true"></constant>
   
   <package name="a" extends="struts-default" namespace="/">
   		<action name="us*" class="com.struts2.action.Meths" method="{1}">
			<result name="login">/login.jsp</result>
			 <!-- Write your own method here, separated by commas -->
			<allowed-methods>userAdd,Method 1,Method 2,Method 3</allowed-methods>
   		</action>
   </package>
</struts>

Front page, pseudocode.

<%
	String base = request.getScheme() + "://" +
				    request.getServerName() + ":" +
					request.getServerPort() + 
					request.getContextPath();
%>
<a href="<%=base%>/ususerAdd">test</a>

Tested, peek, and finally succeeded.

7. But it's not what I want. There's no way. Just keep on driving.Finally the Emperor did not let me down and found the effect I wanted.Original article address http://blog.csdn.net/maobois/article/details/51854607 (Blogger Summary) The host here is also recommended  http://ask.csdn.net/questions/260958 (final answer)

Take a look at the modified configuration

<struts>
   <!-- Turn on dynamic method matching -->
   <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
   <constant name="struts.devMode" value="true"></constant>
   
   <package name="a" extends="struts-default" namespace="/">
   		 
   		<!-- hot corner  struts2.5 To improve security, add allomethod Such a thing-->
   		 <global-allowed-methods>regex:.*</global-allowed-methods>
   		 
   		<action name="us*" class="com.struts2.action.Meths" method="{1}">
			<result name="login">/login.jsp</result>
   		</action>
   </package>
</struts>

The foreground page is unchanged.At this point, it was finally solved.

8. For the problems encountered, the solutions are summarized so as not to have a bad memory and forget later. It will also surprise the little partner who encountered this problem.

1.1 By enabling dynamic method matching

<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>

1.2 Corresponding additions to package packages

<global-allowed-methods>regex:.*</global-allowed-methods>

Full Configuration

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">


<struts>
   <!-- Turn on dynamic method matching -->
   <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
   <constant name="struts.devMode" value="true"></constant>
   
   <package name="a" extends="struts-default" namespace="/">
   		 
   		<!-- hot corner  struts2.5 To improve security, add allomethod Such a thing-->
   		 <global-allowed-methods>regex:.*</global-allowed-methods>
   		
   		<action name="us*" class="com.struts2.action.Meths" method="{1}">
			<result name="login">/login.jsp</result>
   		</action>
   </package>
</struts>

2.1 There is no need to turn on dynamic method matching configuration

<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>

2.2 Related Configurations

<action name="us*" class="com.struts2.action.Meths" method="{1}">
	<result name="login">/login.jsp</result>
	<allowed-methods>Method 1,Method 2</allowed-methods>
</action>

2.3 If you feel that 2.2 writing out the methods one by one is too cumbersome, you can also write like this

<action name="us*" class="com.struts2.action.Meths" method="{1}">
	<result name="login">/login.jsp</result>
	<allowed-methods>regex:.*</allowed-methods>
 </action>

Here's what I think about here

When to use 1.1 and 2.1

If you're in the same package, you'll need to use this dynamic matching, and 1.1 is obviously better for you.

<package name="">
   	<action name=""></action>
   	<action name=""></action>
   	<action name=""></action>
</package>

Anyway, if only a local <action>is used, choose 2.1


I wipe. Everyone's gone. I should eat too.

Keywords: Java Struts JSP xml Apache

Added by Mr_jmm on Sat, 29 Jun 2019 21:46:20 +0300