这是总结自己在java web开发中的一些经验,写下的同时加深理解吧。。。。
1.java.lang.NullPointerException
原因:空指针异常,所指的对象不存在。用System.out.println()调试输出,看哪里出现问题,在进行追踪。
2. 404异常
原因:报404异常说明程序找不到页面,也就是在服务器端处理完,转到Jsp页面时,找不到需要的jsp页面。
3.
Java web.xml配置404和500错误及异常
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/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">
<!-- 配置错误处理 -->
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
<error-page>
<error-code>505</error-code>
<location>/505.html</location>
</error-page>
<!-- 配置异常处理 -->
<error-page>
<exception-type>javax.servle.ServletException</exception-type>
<location>/error.html</location>
</error-page>
<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>/error.html</location>
</error-page>
</web-app>
异常:
当访问一个action或是servlet的时,可能会出现异常,
struts2中web.xml配置:
<default-action-ref name="pagenotfound"></default-action-ref>?
<action name="pagenotfound">
<result>/pagenotfound.html</result>?
</action>
servlet中web.xml配置:
<error-page>
<exception-type>javax.servle.ServletException</exception-type>
<location>/error.html</location>
</error-page>