Cannot retrieve mapping for action

Source: Internet
Author: User
Tags tld

 

To:

The form tag of struts defines a form of a page. However, the struts tag finds action ing in module config based on the value of action and initializes the action form based on the value of action mapping. Therefore, you need to obtain a module config in the form tag. In this case, obtaining a module config becomes the key to whether the form tag can work normally. If the module config value is incorrect, the corresponding action mapping cannot be found or found, but is not the correct action mapping. This may cause cannot retrieve mapping for {action name} errors or other unexpected errors. The lookup method marked by form contains the process of searching for the module. The lookup method is to first obtain the current module config from the request. If not, obtain the default module config from the servlet context (that is, the module with the module prefix ).
By analyzing the initialization method of actionservlet, we can find that actionservlet saves the initialized module config In the attributes of servlet context, and the attribute name is globals. module_key + prefix, but how does the current module config of the request object come from. After an actionservlet obtains a request, it matches the request URL with the module prefix saved in the servlet context. If the request matches successfully, the attribute name is globals. the module config of module_key + "matched prefix" is returned as the current module config. This process appears in the actionservlet process method. When selecting the module, it will follow the above rules, select the current module config and save it to the request attribute globals. module_key. And transfer the instance to the requestprocessor object.
From the above analysis, we can see that if the JSP page containing form tag correctly associates itself with a module, you need to put the current module config object in the request in advance, however, the action for storing module config to request is completed in actionservlet. Therefore, the page is only after processing an Acton (during the process of processing an action, the current module is matched according to the Action URL, and save it in the request), and redirect to a JSP page by redirect = false, so that the JSP page can be correctly associated with the module, otherwise, all files will be associated with the default module config. For example, if you directly type a jsp url in the address bar, all JSP files will be associated with the default module config.

From: http://www.blogbus.com/blogbus/blog/diary.php? Diaryid = 139866

Today, I tried to add the written system login module to our existing module. He did not write it according to the configuration of our project because of some components of the test, we didn't divide the configuration according to our module. After adding the configuration, we re-configured the module information, and the result was not working properly. Error: "cannot retrieve action mapping. It cannot be solved if the power is exhausted. For Web. XML, Struts-config, and module configuration, everything looks very normal, but it just cannot run. It's hard to figure out what went wrong. I thought I was not sure. I had to work overtime at night. Who knows? I can search for the keyword "Action mapping cannot be found" on Google ", the first link is actually the answer to the question! (I have never been able to find the answer once, so I am very excited ^ o ^)

In general, the cause of the problem is,Struts extracts the URL path information of the request when it receives the action request for the first time (Note: JSP requests are not included) and sets the mapping information of the corresponding module to the request.. If you access a JSP page for the first time when entering a module, and submit an action to this module in this JSP page, the action mapping cannot be found. This is because, when accessing this module, JSP is used, and no action of this module is accessed, therefore, the actionservlet of struts does not have time to set the mapping of this module to the request. Naturally, the action of this module cannot be found.

Therefore, this introduces an agreement,That is, try to avoid direct access to JSP in the system. If you want to access it, use action to forward. Although it seems a little troublesome, security and robustness will be improved.

From: http://dev.csdn.net/article/55/55476.shtm

Struts 1.1 supports multi-module development. Create a new module (New-> Struts 1.1 Module) in the myeclipse web application project ),
Add form action actionforward (New-> Struts 1.1 Action, form & JSP) in sequence. Sometimes, myeclipse cannot find the form you just added and add it manually. It's no big deal. The Web. XML template of myeclipse does not comply with the standards and needs to be modified manually. TLD files are not quite correct either. Instead, they can be replaced by TLD files that have previously been used as projects.

The following are two questions that have plagued me for a long time.

1) if the security module contains
<Action> </Action> Path = "/usersecuritycheck"
Type = "com. SCS. Presentation. Security. usersecuritycheckaction"
Name = "userloginform" Scope = "request"
Input = "/init. Do">
<Forward name = "loginsucceed" Path = "/mainmenu. jsp"> </forward>

In this example, pay attention to mainmenu. there is a/In front of JSP, and actionservlet will look for this JSP in the current module, that is, mainmenu. JSP should be placed in the/% webroot %/security/directory, instead of directly under/% webroot % /.

2) The form tag of struts defines a form of a page. However, the struts tag needs to search for Action mapping in module config based on the value of action, initialize the action form based on the value of action mapping. Therefore, you need to obtain a module config in the form tag. In this case, obtaining a module config becomes the key to whether the form tag can work normally. If the module config value is incorrect, this will cause the cannot retrieve mapping for {action name} error. The search method is to first obtain the current module config from the request. If not, retrieve the default module config from the servlet context.

Currently, the implementation of Struts framework is like this. Only actionservlet correctly assigns the module config object to the request attribute globals. after module_key, the later JSP page containing form tag that belongs to this module can be correctly linked to the corresponding module config by Struts framework. If programmers/users attempt to send the first request to a module as JSP rather than action, actionservlet will not have the opportunity to do the above preparations (because Web Container will directly process JSP requests, does not forward to actionservlet), then when processing the form tag in JSP, Struts framework will try to find the actionmapping from the default module config (because the module specfic config in the request is still empty, so I have to find it from the default). Generally, this kind of search has no results, and the framework will return the cannot retrieve mapping for thisaction error.

The conclusion is that the first page accessing each module must be requested by Action (rather than JSP requests) to give actionservlet a chance to load the corresponding module config and cache.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.