J2EE Learning Notes (8) It's really a difficult to test struts.

xiaoxiao2021-03-06  51

It is really a good thing, tossing two nights to get a HelloWorld Struts version, let's talk about a little experience.

Development Environment Eclipse MyEClipse (Struts 1.1)

Struts 1.1 supports multi-module development, build new module (new-> struts 1.1 module) in MyEclipse's Web Application Project, and then add Form Action ActionForward (New -> Struts 1.1 Action, Form & JSP). Sometimes MyEclipse can't find the form you just added, you can add it manually, nothing is not too much. MyECLIPSE's Web.xml template does not meet the standard and needs to be changed manually. The TLD file seems to be not right, you can use the TLD that you used to have done the project.

Below is two questions that I have tossed me for a long time.

1) If there is "request" = "/ init.do" Forward name = "loginsucceed" path = "/ mainmenu.jsp" />

In this example, pay attention to the mainmenu.jsp in front of the MAINMENU.JSP, the ActionServlet will find this JSP in the current module, which means that mainmenu.jsp needs to be placed under the /% Webroot% / Security / Directory instead of directly in /% Webroot. %/under

2) The Struts's FORM tag defines a form of a page, but the Struts tag requires the action maping in Module Config according to the value of the action, and initializes the Action Form according to the value of action mapping. Therefore, a Module Config is required in the Form mark. Here, getting which module config is the key to the form of the Form tag, if the acquiring value of Module Config is incorrect, will cause an error in Cannot Retrieve Mapping for {Action Name}. The lookup method is first obtained from the Request to get the current module config, if not found, get the default Module Config from servlet context.

The implementation of the Struts Framework is this. Only the ActionServlet correctly assigns the Module Config object to the property Globals.Module_Key, the JSP page containing the Form TAG is only correct with the struts framework correctly with the corresponding Module config hook. . If the programmer / user tries to make the first request from a module is JSP instead of an action, ActionServlet does not have the opportunity to prepare for the above preparation (because the web container handles the JSP request, not forward to the ActionServlet), then pick When processing the Form TAG in JSP, Struts framework is trying to find the actionmapping from Default Module Config (Module Specfic Config in Request is still empty, so I have to find it from Default), usually this kind of search is not As a result, Framework will return the error of Cannot Retrieve Mapping for thisaction. Conclusion Yes, the first page of access to each module must be by Action request (not JSP request) to load the corresponding module config and cache.

I am very grateful to the following two articles, they help me solve this strange problem, and indirectly leads to the birth of this article. Http://202.100.72.44/news/itschool/pro/pro44134.htmhttp://www.blogbus.com/blogbus/blog/diary.php?diaryid=139866

- = Please pay for valuable advice, and welcome to discuss, thank you! = -

转载请注明原文地址:https://www.9cbs.com/read-82915.html

New Post(0)