(1)如何配置struts的全局出错信息的条转
struts-config.xml文件中出现错误页面,全局跳转
配置文件信息:
<global-forwards>
<forward name="gerror" path="/pub/errorinfo.jsp"></forward>
<forward name="gerrorclose" path="/pub/errclose.jsp"></forward>
<forward name="gclose" path="/pub/close.jsp"></forward>
<forward name="gframeclose" path="/pub/frameclose.jsp"></forward>
</global-forwards>
.java文件:
Class xxAction extends Action{
try{
}catch(Exception e){
e.printStackTrace();
ActionErrors errors = new ActionErrors();
errors.add(Global.WEB_ERROR_KEY, new ActionError(
Global.WEB_ERROR_KEY, "取人员邮件信息失败,请重试!"));
saveErrors(request, errors);
return mapping.findForward(Global.WEB_ERROR_PAGE);
}
}
jsp文件:
<body>
<table height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><html:errors/></td>
</tr>
<tr>
<td><img src='<c:url value="/images/Error.jpg"/>' alt="访问错误,请返回!" width="574" height="229" οnclick="window.history.back(1);" style="cursor: hand;"/></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
注意:这里的jsp文件中点击返回,触发的javascript代码:window.history.back(1);
(2)在web.xml文件中加在多个struts-config.xml配置文件
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>
/WEB-INF/struts-config.xml,/WEB-INF/oa/action/struts-config-workflow.xml
</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
(3)小技巧:
struts的一些常用标签,可能每个页面都要用到,但是每个页面都重复写很罗嗦,这里我们可以把它独立到一个jsp页面上
----taglibs.jsp
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
<%@ taglib prefix="c-rt" uri="/WEB-INF/c-rt.tld" %>
<%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
<%@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld" %>
<%@ taglib prefix="tiles" uri="/WEB-INF/struts-tiles.tld" %>
<%@ taglib prefix="logic" uri="/WEB-INF/struts-logic.tld" %>
<%@ taglib prefix="tag" uri="/WEB-INF/loadingtag.tld" %>
其他的jsp页面进行应用的时候,
<%@ include file="/pub/taglibs.jsp"%>
request.getContextPath()获得项目的当前路径
<script language=javascript src="<%= request.getContextPath() %>/js/ActiveTable.js"></script>
<script language="Javascript1.1" src="<%= request.getContextPath() %>/js/common.js"></script>