有句名言,叫做10000小时成为某一个领域的专家。姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧。

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 36 Weathre ( 9 ) struts2 – exception的更多相关文章

  1. struts2 java.lang.StackOverflowError org.apache.struts2.json.JSONWriter

    1. 问题描述: 页面通过异步访问action,    action的方法通过map封装数据,struts的result的type设置为json,后台报错 六月 25, 2016 6:54:33 下午 ...

  2. java核心技术-(总结自杨晓峰-java核心技术36讲)

    1. 谈谈你对java平台的理解 首先是java最显著的两个特性,一次写入处处运行:还有垃圾收集器gc,gc能够对java内存进行管理回收,程序员不需要关心内存的分配和回收问题 然后谈谈jre和jdk ...

  3. java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter /struts2.1.3以前版本和之后版本区别/新版Eclipse找不到Java EE Module Dependencies选项

    严重: Exception starting filter struts2java.lang.ClassNotFoundException: org.apache.struts2.dispatcher ...

  4. Java后台处理框架之struts2学习总结

    Java后台处理框架之struts2学习总结 最近我在网上了解到,在实际的开发项目中struts2的使用率在不断降低,取而代之的是springMVC.可能有很多的朋友看到这里就会说,那还不如不学str ...

  5. zookeeper_service 出错 java.lang.NoClassDefFoundError: org/I0Itec/zkclient/exception/ZkNoNodeException

    2016-12-18 08:28:07 ContextLoader:358 ERROR - Context initialization failed java.lang.NoClassDefFoun ...

  6. java.lang.NullPointerException org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)

    采用SSH框架时出现了 java.lang.NullPointerException org.apache.struts2.impl.StrutsActionProxy.getErrorMessage ...

  7. java异常——RuntimeException和User Define Exception

    1.RuntimeException public class RuntimeException { public static void main(String[] args) { // TODO ...

  8. Kafka中错误:Unrecognized VM option ‘UseCompressedOops’ Error: Clould not create the Java Vritual Machine. Error: A fatal exception has occurres . Program will exit.

    错误的描述: 在kafka安装目录下,执行 $ bin/zookeeper-server-start.sh config/zookeeper.properties & Unrecognized ...

  9. 错误:java.lang.NoClassDefFoundError: com/project/common/exception/ServiceException 的解决

    问题: 项目编译通过,启动报错误信息java.lang.NoClassDefFoundError: com/project/common/exception/ServiceException. 解决方 ...

随机推荐

  1. 新浪微博客户端(23)-计算Cell内控件的frame

    DJStatusCellFrame.m #import "DJStatusCellFrame.h" #import "DJStatus.h" #import & ...

  2. Socket网络编程(3)--两端通信

    上篇博文:http://www.cnblogs.com/wolf-sun/p/3329558.html 介绍了客户端连接服务端,一对一,多对一的情况,下面实现服务器接收消息的功能.LZ这些弄的比较慢, ...

  3. asp.net过滤数据中有异常数据字符串

    /// <summary> /// 过滤数据 /// </summary> /// <param name="_str"></param& ...

  4. 菜鸟学习Spring Web MVC之二

    有文章从结构上详细讲解了Spring Web MVC,我个菜鸟就不引据来讲了.说说强悍的XP环境如何配置运行环境~~ 最后我配好的环境Tomcat.Spring Tool Suites.Maven目前 ...

  5. php利用淘宝IP库获取用户ip地理位置

    我们查ip的时候都是利用ip138查询的,不过那个有时候是不准确的,还不如自己引用淘宝的ip库来查询,这样准确度还高一些.不多说了,介绍一下淘宝IP地址库的使用. 淘宝IP地址库 淘宝公布了他们的IP ...

  6. 如何在Linux命令行中创建以及展示演示稿

    导读 你在准备一场演讲的时候,脑海可能会先被图文并茂.形象华丽的演示图稿所占据.诚然,没有人会否认一份生动形象的演讲稿所带来的积极作用.然而,并非所有的演讲都需要TED Talk的质量.更多时候,演讲 ...

  7. Opencv Cookbook阅读笔记(四):用直方图统计像素

    灰度直方图的定义 灰度直方图是灰度级的函数,描述图像中该灰度级的像素个数(或该灰度级像素出现的频率):其横坐标是灰度级,纵坐标表示图像中该灰度级出现的个数(频率). #include <open ...

  8. Textview下划线注册用户跳转实现

    在xml中: <TextView android:id="@+id/textView_regtext" android:layout_width="wrap_con ...

  9. HDOJ 1874

    畅通工程续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  10. 【OpenStack】OpenStack系列1之OpenStack本地开发环境搭建&&向社区贡献代码

    加入OpenStack社区 https://launchpad.net/,注册用户(597092663@qq.com/Admin@123) 修改个人信息,配置SSH keys.OpenPGP keys ...