1。JSPデフォルト設定
1.アクセスしたアクションが存在しない場合、ページにエラーメッセージが表示されます。ユーザー例外操作を処理するようにデフォルトのアクションを構成できます。
2。構成方法:
struts.xmlファイルの下に次のコンテンツを追加します。
<default-action-ref name = "index"> </default-action-ref>
インデックスはデフォルトアクションの名前属性値です。
3.デフォルトのアクションを構成した後、対応する名前空間にアクセスするアクションがない場合、デフォルトのアクション処理に自動的にジャンプします。
4。例
web.xml:
<?xml version = "1.0" encoding = "utf-8"?> <web-appバージョン= "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instcance" 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 < <filter-name> struts2 </filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.stretspareandexecutefilter </filter-class> </filter> <フィルターマッピング> <filter-name> struts2 </filternam> <urtern> </url-mappn>
struts.xml:
<?xml version = "1.0" encoding = "utf-8"?> <!doctype struts public " - // apacheソフトウェア財団// 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" /> <incread file = "emple.xml" /> <package name = "default" namesspace = " /" extends = "struts-default"> <default-ref name = " />> <oftion name = < type = "redirectaction"> <param name = "actionname"> helloworld </param> <param name = "namespace">/example </param> </result> </action> </package> </package> - > <! - constant name = "struts.devmode" value = "true"/> <construts.i18n. name = "user" namespace = "/" extends = "struts-default"> <default-action-ref name = "index"> </default-action-ref> <action name = "index> <result>/index.jsp </result> </action> </package> </struts>
index.jsp:
<%@ページ言語= "java" import = "java.util。*" pageencoding = "gb18030"%> <%string path = request.getcontextpath(); string basepath = request.getscheme()+"://"+request.getservername()+":"+requestserverport.+path+" " - // w3c // dtd HTML 4.01 Transitional // En"> <HTML> <head> <head> <base href = "<%= basepath%>" rel = "real =" real = "real =" real = "real =" real = title> <meta http-equiv = "pragma" content " content = "no-cache"> <meta http-equiv = "compies" content = "0"> <meta http-equiv = "keywords" content = "keyword11、keyword2、keyword3"> <meta http-equiv = "description" content = "これは私のページです"> <! rel = "外部nofollow"> - > </head> <body> magciのブログへようこそ! > 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 = "names">/example </param> - > </result> </action name> <action nam name = "toindex">/web-inf/jsps/index.jsp </result> <result name = "toadminlogin">/web-inf/jsps/jsps/admin/admin_login.jsp </result> <! - ajax-> <result name = "ajaxinsertonecallback" type = "json"> <param name = </<
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。