1. JSP Standardeinstellungen
1. Wenn die auf zugegriffene Aktion nicht vorhanden ist, wird auf der Seite eine Fehlermeldung angezeigt. Sie können die Standardaktion konfigurieren, um Benutzerausnahmeberationen zu verarbeiten.
2. Konfigurationsmethode:
Fügen Sie den folgenden Inhalt unter die Datei struts.xml hinzu:
<Standard-action-ref name = "index"> </default-action-ref>
wobei der Index der Namensattributwert der Standardaktion ist;
3. Nach der Konfiguration der Standardaktion werden im entsprechenden Namespace keine Aktion zugegriffen, wenn sie automatisch zur Standardaktionsverarbeitung springt.
4. Beispiel
web.xml:
<? xsi:schemaLocation="http://java.sun.com/xml/ns/javaee ; http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <welcome-file-list> <welcome-file>hello.jsp</welcome-file> </welcome-file-list> <filter> <Filter-name> Struts2 </filter-name> <filterklasse> org.apache.struts2.dispatcher.ng.filter.strutsprepareAndexecuteFilter </Filterklasse> </Filter> <Filter-Mapping> <Filter-Stuts2 </filter-name> <urlpattern> </filter-name> <urlpattern> </filter-name> <urlpattern>/*</filter-name> <urlpattern>/*</aveNname </filter-mapping> </web-App>
Struts.xml:
<? name = "strutss.enable.dynamicMethodinVocation" value = "false" /> <Constant name = "strut.DevMode" value = "false" /> <inclydedatei = "example.xml" /> <paketname = "Standard" namespace = " /" extends = "stuts-default"> <resultation-action-ref name "ideen"> indefault "> <resultation-action-ref name" ideen = "> indefault"> <resultation-action-ref name "ideen ="> indefault "> <resultation-ref-name". type = "redirectAction"> <param name = "actionName"> helloWorld </param> <param name = "namespace">/Beispiel </param> </result> </action> </package> <!-Fügen Sie hier Pakete hinzu-> <Constant Name = "Struts.DevMode" value = "true"/> <constant name = "struts.i18.encoding". name = "Benutzer" namespace = "/" extends = "struts-default"> <default-action-ref name = "index"> </default-action-ref> <actionname = "index"> <relots> /Index.jsp </result> </action> </paket> </struts>
index.jsp:
<%@ page Language = "java" import = "java.util. "-// w3c // dtd html 4.01 transitional // en"> <html> <head> <base href = "<%= basepath%>" rel = "external nofollow"> <Titel> Index </title> <meta http-äquiv = "pagma" content = "no-cache"> <meta http-äquiv = "cache" --no-cache " content = "no-cache"> <meta http-äquiv = "expires" content = "0"> <meta http-äquiv = "keywords" content = "keyword1, keyword2, keyword3"> <meta http-äquiv = "Beschreibung" content = "is My Page"> <! rel = "externer nofollow"> -> </head> <body> Willkommen in Magcis Blog! > MGC/MAGC/MAGCI/123456 </a> <br/> </body> </html>
2. Aktion Standardeinstellungen Weiterleiten
<!-- Default action --> <default-action-ref name="index" /> <action name="index"> <result type="redirectAction"> <param name="actionName">page_toIndex</param> <!-- <param name="namespace">/example</param> --> </result> </action> <action name="page_*" method="{1}"> <result name = "toIndex">/web-inf/JSPS/index.jsp </result> <result name = "toadminLogin">/web-inf/jSPS/admin/admin_login.jsp </result> <!-ajax-<result name = "ajaxinsertoneCallback" type = "Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.