1. การตั้งค่าเริ่มต้น JSP
1. เมื่อไม่มีการดำเนินการเข้าถึงหน้าจะแสดงข้อความแสดงข้อผิดพลาด คุณสามารถกำหนดค่าการดำเนินการเริ่มต้นเพื่อจัดการการดำเนินการยกเว้นผู้ใช้
2. วิธีการกำหนดค่า:
เพิ่มเนื้อหาต่อไปนี้ภายใต้ไฟล์ struts.xml:
<default-action-ref name = "index"> </default-action-ref>
โดยที่ดัชนีคือค่าแอตทริบิวต์ชื่อของการดำเนินการเริ่มต้น
3. หลังจากการกำหนดค่าการดำเนินการเริ่มต้นหากไม่มีการดำเนินการที่จะเข้าถึงในเนมสเปซที่เกี่ยวข้องมันจะข้ามไปยังการประมวลผลการดำเนินการเริ่มต้นโดยอัตโนมัติ
4. ตัวอย่าง
web.xml:
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <web-app version = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http://ww.w3.org/200 XSI: schemalocation = "http://java.sun.com/xml/ns/javaee; http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" <Tilter-Name> struts2 </filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter </filter-class> </ilter> </ตัวกรอง-แมป> </eb-app>
struts.xml:
<? XML เวอร์ชัน = "1.0" การเข้ารหัส = "UTF-8"?> <! Doctype struts สาธารณะ "-// Apache Software Foundation // dtd struts การกำหนดค่า 2.0 // en" "http://struts.apache.org/dtds/struts-2.0.dtd" name = "struts.enable.dynamicmethodinVocation" value = "false" /> <constant name = "struts.devmode" value = "false" /> <รวมไฟล์ = "example.xml" /> <package name = "default" namespace = "Exteds =" struts-default " type = "redirectaction"> <param name = "actionName"> helloWorld </param> <param name = "namespace">/ตัวอย่าง </param> </result> </action> </package>-> <! name = "user" namespace = "/" extred = "struts-default"> <default-action-ref name = "index"> </default-action-ref> <action name = "index"> <result> /index.jsp </result> </action>
index.jsp:
<%@ page language = "java" import = "java.util.*" pageencoding = "GB18030"%> <%String Path = request.getContextPath (); String basepath = request.getScheme ()+"//" "-// w3c // dtd html 4.01 transitional // en"> <html> <head> <base href = "<%= basepath%>" rel = "external nofollow"> <title> ดัชนี </title> <meta http-equiv = "pragma" content = "no-cache"> <meta http-equiv = "Expires" content = "0"> <meta http-equiv = "คำหลัก" content = "keyword1, keyword2, keyword3"> <meta http-equiv = "คำอธิบาย" content = "นี่คือหน้าของฉัน" rel = "ภายนอก nofollow"> -> </head> <body> ยินดีต้อนรับสู่บล็อกของ Magci! <br/> <a href = "magci/magc" rel = "ภายนอก nofollow"> magci/magc </a> <br/> <a href = "mgc/magc/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> <!-<param = "namespace">/ตัวอย่าง </param> name = "toindex">/web-inf/jsps/index.jsp </result> <ชื่อผลลัพธ์ = "toadminlogin">/web-inf/jsps/admin/admin_login.jsp </result> <!
ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้ ฉันหวังว่ามันจะเป็นประโยชน์ต่อการเรียนรู้ของทุกคนและฉันหวังว่าทุกคนจะสนับสนุน wulin.com มากขึ้น