Java Hour 36 Weathre ( 9 ) struts2 – exception
2013-11-14 20:23
253 查看
有句名言,叫做10000小时成为某一个领域的专家。姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧。
Hour 35
如上所述,在配置文件里面加入全局的异常映射。
插入指定action 的异常处理
增加日志功能,这里使用的是拦截器
一些基本的验证功能已经自带了,这个可以留待过会儿practice.
所以这里必须的。
基本的CURD 操作这里需要写大概4个映射,每个都这样写要疯了的。
使用通配符以后,这个世界就妥妥的啦。
接下去正式将这些学习的知识点发挥作用的时候了。
继续我们未完成的Weather 页面。
这些知识最基本的教程,让我们明白大概的struts2 组织结构,后续的有annotation 之类的可以更优雅的方式实现相同的功能,让我们先使用我们已经拥的的成果学以致用,而后再来改进。
Hour 35
Exception Handling
直接添加全局性的异常处理的映射,既然是映射就必然在我们的映射配置文件里面。<package name="basicstruts2" extends="struts-default"> <global-results> <result name="securityerror">/securityerror.jsp</result> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException" result="securityerror" /> <exception-mapping exception="java.lang.Exception" result="error" /> </global-exception-mappings> <action name="index"> <result>/index.jsp</result> </action> <action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute"> <result name="success">/HelloWorld.jsp</result> </action>
如上所述,在配置文件里面加入全局的异常映射。
插入指定action 的异常处理
<action name="actionspecificexception" class="org.apache.struts.register.action.Register" method="throwSecurityException"> <exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException" result="login" /> <result>/register.jsp</result> <result name="login">/login.jsp</result> </action>
增加日志功能,这里使用的是拦截器
继续输入的验证功能
这里使用Struts2 自带的xml 配置文件验证功能。一些基本的验证功能已经自带了,这个可以留待过会儿practice.
通配符
如果没有通配符,这个action 文件将会迅速的膨胀到一个令人发指的地步。所以这里必须的。
<action name="createPerson" class="org.apache.struts.tutorials.wildcardmethod.action.PersonAction" method="create"> <result name="input">input.jsp</result> <result name="success">view.jsp</result> </action> <action name="editPerson" class="org.apache.struts.tutorials.wildcardmethod.action.PersonAction" method="edit"> <result name="input">input.jsp</result> <result name="success">view.jsp</result> </action>
基本的CURD 操作这里需要写大概4个映射,每个都这样写要疯了的。
<action name="*Person" class="org.apache.struts.tutorials.wildcardmethod.action.PersonAction" method="{1}"> <result name="success">view.jsp</result> <result name="input">input.jsp</result> </action>
使用通配符以后,这个世界就妥妥的啦。
What’s The Next ?
感谢官方站点提供的入门:http://struts.apache.org/release/2.1.x/docs/tutorials.html接下去正式将这些学习的知识点发挥作用的时候了。
继续我们未完成的Weather 页面。
这些知识最基本的教程,让我们明白大概的struts2 组织结构,后续的有annotation 之类的可以更优雅的方式实现相同的功能,让我们先使用我们已经拥的的成果学以致用,而后再来改进。
相关文章推荐
- Java Hour 35 Weather ( 8 ) struts2 – message resource
- Java Hour 32 Weather ( 5 ) struts2 – Action class
- Java Hour 34 Weather ( 7 ) struts2 – validate
- filter struts2 java.lang.ClassNotFoundException异常
- struts2 java.lang.ClassNotFoundException: org.apache.commons.lang.xwork.StringUtils
- struts2的java.lang.NoSuchMethodException异常处理 \
- 关于在struts2中使用java注解报异常 java.lang.reflect.InvocationTargetException
- Struts2请求加上时间戳出现java.lang.NumberFormatException: For input string:
- Struts2 DateTimepicker标签 和 java.lang.RuntimeException: Invalid action class configuration that refer
- Struts2配置问题java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- struts2下载文件时出现:java.lang.ClassCastException: java.io.ByteArrayInputStream cannot be cast to 错误
- org.apache.struts2.json.JSONException: java.lang.IllegalAccessException
- Struts2环境下Tomcat启动异常:Exception starting filter struts2,报了一个java.lang.ClassNotFoundException
- struts2项目 tomcat报错:严重: Dispatcher initialization failed java.lang.RuntimeException
- Struts2 DateTimepicker标签 和 java.lang.RuntimeException: Invalid action class configuration that references an unknown class named [YunWeiAction]
- Struts2启动过程中报错java.lang.ClassNotFoundException完美解决方案
- struts2 java.lang.ClassNotFoundException: org.apache.commons.lang.xwork.StringUtils
- java.lang.NullPointerException(struts2开发错误记录)
- struts2做项目报错:java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 的解决方法
- struts2 报错:java.lang.NullPointerException: Source must not be null