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 version = "2.5"xmlns = "http://java.sun.com/xml/xml/ns/javaee"xmlns : xsi = "http://www.w3.org/2001/xmlschema-instance. xsi : schemalocation = "http://java.sun.com/xml/ns/javaee; http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd <filter-name> struts2 </filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecuteFilter </filter-class> </필터> <filter-mapping> <filter-name> struts2 </filter-name> <url-pattern>/* </필터 매핑> </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> < 이름 = "struts.enable.dynamicmethodinvocation"value = "false" /> <constant name = "struts.devmode"value = "false" /> <포함 파일 = "example.xml" /> <package name = "default"namespace = " /"extends = "struts-default"> 유형 = "리디렉션"> <param name = "actionName"> helloworld </param> <param name = "namespace">/example </param> </result> </action> </package>-> <!-여기에 패키지를 추가합니다-> <constant name = "struts.devmode"value = "true"/> <struts.i18n. Emoding " value = "gbk"> </constant> <package name = "user"namespace = "/"extends = "struts-default"> <default-Action-Ref name = "index"> </default-action-ref> <action name = "index"> result>/index.jsp </action> </strut> </struts>
index.jsp :
<%@ page language = "java"import = "java.util.*"pageEncoding = "gb18030"%> <%string path = request.getContextPath (); String BasePath = request.getScheme () : // "+request.getServerName ()+": "+request.getserverport ()+path+"; "-// w3c // dtml 4.01 과도기 // en"> <html> <head> <base href = "<%= basepath%>"rel = "외부 nofollow"> <title> index </title> <meta http-equiv = "pragma"content = "no-cache"> <meta http-equiv = "cache-control". content = "no-cache"> <meta http-equiv = "만료"content = "0"> <meta http-equiv = "keywords"content = "keyword1, keyword2, keyword3"> <meta http-equiv = "description ="이것은 내 페이지입니다 ">-<link rel ="text/css " href = "styles.css"rel = "external nofollow"> -> -> </head> <hod> Magci의 블로그에 오신 것을 환영합니다! <br/> <a href = "magci/magc"rel = "external nofollow"> magci/magc </a> <a href = "mgc/magci/123456"external nofolly ". > mgc/magc/magci/123456 </a> <br/> </body> </html>
2. 조치 기본 설정 전달
<!-> <default-Action-Ref name = "index"/> <action name = "index"> <result type = "recction"> <param name = "actionname"> page_toindex </param> <!-<param name = "namespace">/exames </param>-> </action> <action name = "page_*" 이름 = "toindex">/web-inf/jsps/index.jsp </result> <result name = "toadminlogin">/web-inf/admin/admin_login.jsp </result> <!-ajax-> <result name = "ajaxinsertonecallback"= "json">
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.