Struts2-Learning Note Series (8)-Exception handling

Source: Internet
Author: User

Custom exceptions thrown in the background

1  PublicString Execute ()throwsException {2 3     if(GetUser (). Equalsignorecase ("User"))4     {5         Throw NewZcxexception ("Custom Exception");6     }7     if(GetUser (). Equalsignorecase ("SQL"))8     {9         Throw NewJava.sql.SQLException ("User name cannot be SQL");Ten     } One     if(GetUser (). Equals ("Zcx")) A     { -Addactionmessage ("Server Prompt! "); -         returnSUCCESS; the     } -     returnERROR; -}

Struts Configuration exception Handling

1  2 3< PackageName= "Zcx.controller" namespace= "/"extends= "Struts-default" >4<!--define a global result map--5<global-results>6<!--definition when SQL, root two logical exceptions all correspond exception.jsp page--7<result name= "SQL" >/WEB-INF/content/exception.jsp</result>8<result name= "Root" >/WEB-INF/content/exception.jsp</result>9</global-results>Ten  One<!--defining global exception mappings-- A<global-exception-mappings> -<!--When an SqlException exception is encountered in the action, -The system will be transferred to the result of name SQL-- the<exception-mapping exception= "java.sql.SQLException" result= "sql"/> -<!--When an exception exception is encountered in the action, -The system will be transferred to the result of name root-- -<exception-mapping exception= "Java.lang.Exception" result= "root"/> +</global-exception-mappings> -  +  A<action name= "Login"class= "Zcx.controller.LoginAction" > at<!--defines a local exception map, and when an myexception exception is encountered in the action, -The system will be transferred to the result of the name my-- -<exception-mapping exception= "zcx.controller.ZcxException" result= "my" ></exception-mapping> -<result name= "My" >/WEB-INF/content/exception.jsp</result> -<result name= "Error" >/WEB-INF/content/error.jsp</result> -</action> in  -<!--to handle all action--> to<action name= "*" > +<!--return the corresponding page-- -<result>/WEB-INF/content/{1}.jsp</result> the</action> *  $ Panax Notoginseng</ Package>

Struts2-Learning Note Series (8)-Exception handling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.