1. الإعدادات الافتراضية JSP
1. عندما لا يكون الإجراء الذي تم الوصول إليه موجودًا ، ستعرض الصفحة رسالة خطأ. يمكنك تكوين الإجراء الافتراضي لمعالجة عمليات استثناء المستخدم ؛
2. طريقة التكوين:
أضف المحتوى التالي أسفل ملف struts.xml:
<default-action-ref name = "index"> </default-action-ref>
حيث يكون الفهرس قيمة سمة الاسم للإجراء الافتراضي ؛
3. بعد تكوين الإجراء الافتراضي ، إذا لم يكن هناك إجراء يمكن الوصول إليه في مساحة الاسم المقابلة ، فسيقفز تلقائيًا إلى معالجة الإجراء الافتراضية.
4. مثال
web.xml:
<؟ XSI: schemalocation = "http://java.sun.com/xml/ns/javaee ؛ http://java.sun.com/xml/ns/javaee/web-app_2_5 <filter-name> struts2 </filter-name> <ilter-class> org.apache.struts2 </filter-mapping> </bil-app>
struts.xml:
<؟ name = "struts.enable.dynamicMethodInvocation" value = "false" /> <name name = "struts.devmode" value = "false" /> <include file = "example.xml" /> <package name = "expault" type = "redirectaction"> <param name = "actionName"> helloWorld </param> <param name = "namepace">/example </param> </result> </uction> </package>-> <!-أضف الحزم هنا-> <name constant> name = "user" namepace = "/" extendes = "struts-default"> <default-action-ref name = "index"> </action-action-ref> <action name = "index"> /index.jsp </sropegan
index.jsp:
<٪@ page language = "java" import = "java.util.*" pageencoding = "gb18030" ٪> <٪ string path = requestContextPath () ؛ string basepath = request.getscheme ()+": //" request.getServerName ()+ "-// w3c // dtd html 4.01 Transitional // en"> <html> <head> <base href = "<٪ = basepath ٪>" rel = "external nofollow"> <title> فهرس </title> </meta http-equiv = "content =" no-cache content = "no-cache"> <meta http-equiv = "Expires" content = "0"> <meta http-equiv = "keywords" content = "keyword1 ، keyword2 ، keyword3"> <meta http-equiv = "description description" content = "is is my part" <! rel = "خارجي nofollow"> -> </head> <body> مرحبًا بكم في مدونة Magci! <br/> <a href = "magci/magc" rel = "خارجي nofollow"> magci/magc </a> <br/> <a href = "mgc/magci/magci/123456 > MGC/MAGC/MAGCI/123456 </a> <br/> </body> </html>
2. إعادة توجيه الإعدادات الافتراضية الإجراء
<!-الإجراء الافتراضي-> <default-action-ref name = "index"/> <action name = "index"> <result type = "redirectaction"> <param name = "actionName"> page_toindex </param> <! name = "toindex">/web-inf/jsps/index.jsp </result> <result name = "toadminlogin">/web-inf/jsps/admin/admin_login.jsp </sropear> <!
ما سبق هو كل محتوى هذه المقالة. آمل أن يكون ذلك مفيدًا لتعلم الجميع وآمل أن يدعم الجميع wulin.com أكثر.