在Struts中对于exception出现的情况下,可以使用
代码
- <global-exceptions>
- <exception key="errors.message" type="java.lang.Exception" path="/errorpage.jsp" scope="request"/>
- </global-exceptions>
<script type="text/javascript">render_code();</script>
来指定错误页面
我希望在页面上显示
详细的错误信息,如何编写errorpage.jsp页面呢?
web.xml设定
代码
-
- <error-page>
- <exception-type>org.xiaohanne.simplemvc.exception.ErrorPageException</exception-type>
- <location>/error/error.jsp</location>
- </error-page>
<script type="text/javascript">render_code();</script>
error.jsp 这个页面因为isErrorPage="true"所以能取默认的exception
代码
- <%@page contentType = "text/html;charset=gb2312" %>
- <%@page isErrorPage="true"%>
- <html>
- <head>
- <title>错误处理</title>
- <meta http-equiv="Expires" content="">
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <link rel="stylesheet" href="css.css">
- <body color=#FF0000>
- <br><br><br>
- <table width="400" bgcolor=#EEEEFF align=center border="0" cellspacing="0" cellpadding="0">
- <tr class=th height=22><td colspan=10>&错误提示</td></tr>
- <tr bgcolor=#CCCCEE height=1><td colspan=10></td></tr>
- <tr>
- <td width=30 rowspan="4">&</td>
- <td>
- <font color=#0000FF><font color="#0000FF">错误信息为:<%=exception.getMessage()%>
- <%--根据配置文件或url参数决定是否显示--%>
- <%String sIsDebug=request.getParameter("debug");
- if(sIsDebug==null||sIsDebug.equals("")) sIsDebug="false";
- if(org.xiaohanne.simplemvc.config.Configurator.isDebug()||sIsDebug.equals("true")){%>
- <hr>
- 错误详细信息(供管理人员调试):<%=exception.toString()%>
- <hr>
- 错误堆栈(供管理人员调试):<br><%=((org.xiaohanne.simplemvc.exception.ErrorPageException)exception).toTrace()%>
- <%}%>
- </font></font>
- </td>
- <td height="69">&</td>
- </tr>
- <tr height=30 valign=center>
- <td valign="top" align="right"><a href='javascript:history.go(-1);'>返回上页</a></td>
- </tr>
- <tr bgcolor=#CCCCEE height=1><td colspan=10></td></tr>
- </table>
- </body>
- </html>
补上ErrorPageException.toTrace()的定义
代码
- package org.xiaohanne.simplemvc.exception;
-
-
-
-
-
- public abstract class ErrorPageException extends ServletException {
- protected String _errorStr=super.toString();
-
- public String toTrace(){
- String s="\n"+this.getClass().toString();
- StackTraceElement[] trace = this.getStackTrace();
- for (int i=0; i < trace.length; i++)
- s+="\n " + trace[i];
- return s;
- }
- }
分享到:
相关推荐
struts struts的错误处理 struts控制界面输出 struts struts的错误处理 struts控制界面输出
Struts2资源文件在jsp页面中显示乱码解决
在页面中使用标签。 下面以一个自定义的分页标签为例,进行说明。 其实,开发自定义标签并不需要Struts2的支持,一般情况下,只需要继承javax.servlet.jsp.tagext.BodyTagSupport类,重写doStartTag,doEndTag等...
Apache Struts 2.5.28.3是一个优雅的、可扩展的框架,用于创建企业级 ...它可以在完整发行版中使用,也可以作为单独的库、源代码、示例和文档发行版使用。Struts 2.5.28.3 是 2.5 系列中 Struts 的“最佳可用”版本。
Java.Web开发JSP.Servlet.Struts.Spring.Hibernate.Ajax.rar
3. 编写登录页面(login.jsp)、登录成功(login_success.jsp)和登录失败页面(login_fail.jsp); 4. 编写Ation实现类,实现execute()方法;登录成功返回SUCCESS,并跳转到login_success.jsp;否则返回FAIL,并跳转到...
jsp通过Ajax无刷新获取Action返回的模拟数据,然后通过struts2转化成json数据返回页面....这里面Map,List,对象等等,一些常用的操作都有。主要的代码在Action和 json.js里面。适合新手入门
利用Struts 2标签创建ex3.jsp页面,此页面提交给tag.action,在structs.xml中配置这个action的转发视图为result.jsp在result.jsp页面中显示ex3.jsp页面控件的值。(源代码和实验报告)
具体要求是在loginAction类中分别用login()和registered()处理用户登录和注册的过程,分别创建login.jsp和register.jsp两个页面实现登录和注册的输入,这两个页面提交给loginAction中的两个方法进行业务处理,...
Java.Web整合开发王者归来.JSP+Servlet+Struts+Hibernate+Spring.part2.rar
功能: 在登录页面login.jsp中输入用户名admim和密码123456后,单击登录按钮后跳转到success.jsp页面; 否则页面跳转到login.jsp页面等待用户输入;...6. 创建struts.xml配置Action 7. 部署和运行struts2项目
struts2中action如何获取jsp页面参数1.rar
struts2中action如何获取jsp页面参数1.pdf
struts2 中action 如何获取jsp 页面参数1.pdf
org.apache.struts2.views.freemarker, org.apache.struts2.views.freemarker.tags, org.apache.struts2.views.jsp, org.apache.struts2.views.jsp.iterator, org.apache.struts2.views.jsp.ui, org.apache.struts2...
1.3. Struts 框架中的组件.3 1.3.1. Struts配置文件.3 1.4. ActionServlet类6 1.4.1. ActionServlet配置6 1.4.2. ActionServlet方法7 1.5. ActionMapping 类8 1.6. Action 类.8 1.6.1. Action 类的方法.9 1.7. ...
10.3.2 编写JSP页面helloWorld.jsp 10.3.3 编写控制器HelloWorldController.java 10.3.4 建立Spring的配置文档dispatcherServlet-servlet.xml 10.3.5 配置web.xml 10.3.6 启动Tomcat运行程序 10.4 Spring 的视图...