Struts2, best practice using the method = {1}

I am new to Struts 2 and I came across this syntax (recommended in the tutorial).

<action name="Register_*" method="{1}" class="Register">
    <result name="input">/member/Register.jsp</result>
    <result type="redirectAction">Menu</result>
</action>

I understand that it calls the Register method. {1}. The problem is that the user can enter another (random) value and cause a 500 error (which will be correctly registered as an error).

How can this be prevented?

+3
source share
2 answers

First of all, it will not call the Register method. {1}. It will call Register_ {1}, where {1} can be an action type (usually edit, show etc)

Means the url is actually

Register_View
Register_Edit
e.t.c.

So, if the user manually changes the URL to the fact that it is not, for example

Register_methodThatDoesNotExist

struts 2 .

? -, , URL-, ( 404)

?

Update:

500 , ( ) . . "Default Default Default" struts 2 wiki

http://cwiki.apache.org/WW/action-configuration.html

+1

:

  <action name="*/*" class="{1}Action" method="{2}">
       <interceptor-ref name="CustomAuthStack" />       
            <result>/pages/{1}/{2}.jsp</result>
            <result name="input">/pages/error/denied.jsp</result>
            <result name="logout">/pages/error/denied.jsp</result>

            <!-- methods that come back to listing after processing -->
            <result name="remove" type="redirectAction">{1}/list</result>
            <result name="save"   type="redirectAction">{1}/list</result>
            <result name="enable"   type="redirectAction">{1}/list</result>

   ....

   </action>

, myapp/users/list,

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

strus.xml.

, :

action → UserAction jsp ----- > users/list.jsp

.

+8

Source: https://habr.com/ru/post/1706111/


All Articles