1. Pengaturan default JSP
1. Ketika tindakan yang diakses tidak ada, halaman akan menampilkan pesan kesalahan. Anda dapat mengonfigurasi tindakan default untuk menangani operasi pengecualian pengguna;
2. Metode Konfigurasi:
Tambahkan konten berikut di bawah file struts.xml:
<Default-action-Ref name = "index"> </default-action-ref>
di mana indeks adalah nilai atribut nama dari tindakan default;
3. Setelah mengkonfigurasi tindakan default, jika tidak ada tindakan yang akan diakses di namespace yang sesuai, itu akan secara otomatis melompat ke pemrosesan tindakan default.
4. Contoh
Web.xml:
<? Xml Version = "1.0" encoding = "UTF-8"?> <Web-app Versi = "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: xsi = "http:/www.w3.org/2001 =" http:/www.w3.org/200 XSI: schemalocation = "http://java.sun.com/xml/ns/javaee; http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <celcome-file-file-file-file-file-file-file.jsp_2_5.xsd "> <celcome-file-file-file-file--file-file> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
struts.xml:
<? Xml Version = "1.0" encoding = "UTF-8"?> <! Doctype Struts Public "-// Apache Software Foundation // DTD Struts Configuration 2.0 // en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-<putsen "neomputs- <puts.0.dtd"> <struts> <! value="false" /> <constant name="struts.devMode" value="false" /> <include file="example.xml"/> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <action name="index"> <result type="redirectAction"> <param name="actionName">HelloWorld</param> <param name="namespace">/example</param> </result> </action> </package> --> <!-- Add packages here --> <constant name="struts.devMode" value="true" /> <constant name="struts.i18n.encoding" value="GBK"></constant> <package name="user" namespace = "/" extends = "struts-default"> <default-action-ref name = "index"> </default-action-ref> <action name = "index"> <rances> /index.jsp </rence> </ctive> </package> </struts>
index.jsp:
<%@ page language = "java" import = "java.util.*" pageEncoding = "GB18030"%> <%string path = request.getContextPath (); string basepath = request.getscheme ()+":/"+request.getServername ()+":"+miring. "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>" rel="external nofollow" > <title>Index</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href = "styles.css" rel = "eksternal nofollow"> -> </head> <body> Selamat datang di blog Magci! <Br/> <a href = "magci/magc" rel = "nofollow eksternal"> magci/magc </a> <r/> <a href = "magc/magci/magc </a> <bR /> <a href =" mgc/magc/magc/magc/123 "<br /> <a href =" mgc/magc/magc/magci/123 " > MGC/MAGC/MAGCI/123456 </a> <br /> </body> </html>
2. Tindakan Pengaturan Default Penerusan
<!-Tindakan default-> <default-action-ref name = "index"/> <action name = "index"> <result type = "redirectaction"> <param name = "actionName"> page_toIndex </param> <!-<param name = "namespace">/contoh </param>-> </result> </Action> </Action name = "Page"/Contoh </param>-> </result> </Action> </Action name = "Page"/CONTOH "" name = "ToIndex">/web-inf/jsps/index.jsp </result> <result name = "toAdminlogin">/web-inf/jsps/admin/admin_login.jsp </hasilnya> <!-ajax-> <hasil name = "AJAXInSerTonecallback" type = "json"> <"Action =" ACTOCE "</PARONT/PARINT/ACTOCE </ACTY" </ACTY/ACTOCE </ACTY/ACTOCE </Action> </paron> </paron> </paron/param = "ACTOCE" </ACTY/ACTOCE </ACTY/ACTOCETONTONCALLBack
Di atas adalah semua konten artikel ini. Saya berharap ini akan membantu untuk pembelajaran semua orang dan saya harap semua orang akan lebih mendukung wulin.com.