9、bug修正及删除功能实现

bug修正及删除功能实现
1、log4j-1.2.15版本bug,建议不要使用它,而建议使用log4j-1.2.14
引用
After upgrading from 1.2.14 to 1.2.15 the following error show up during
shutdown:
log4j:ERROR LogMananger.repositorySelector was null likely due to error in
class
reloading, using NOPLoggerRepository.

No errors at all with 1.2.14

This probably is related to bug 40212

2、对应${org.parent.name},当org为顶级机构时候回报错空指针异常,修改
Organization.hbm.xml添加 not-found="ignore":
<many-to-one column="pid" access="field" name="parent" not-found="ignore"/>

Organization.java添加not-found="ignore":
      
/**
	 * @hibernate.many-to-one
	 * column="pid" not-found="ignore"
	 */
	private Organization parent;
index.jsp修改
<td align="center" vAlign="center">
	<c:out value="${org.parent.name}"></c:out>
</td>


<td align="center" vAlign="center">
<c:if test="${!empty org.parent.name}">
	<c:out value="${org.parent.name}"></c:out>
</c:if>
</td>

3、添加机构的唯一编号,修改OrgManagerImpl.java的addOrg(Organization org, int parentId)方法为:
    
public void addOrg(Organization org, int parentId) {
        if(parentId != 0)
        	org.setParent((Organization)getHibernateTemplate().load(Organization.class, parentId));
       getHibernateTemplate().save(org);
       //TODO 设置机构的唯一编号
       org.setSn(org.getParent() == null ? "" + org.getId(): org.getParent().getId() + "_" + org.getId());
       getHibernateTemplate().update(org);
	}
4、完成删除功能:
public_del_success.jsp文件:
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>删除记录成功</title>
<script type="text/javascript">
function closewindow(){
	window.returnValue = true;
	window.close();
}
function clock(){
	i = i -1;
	if(document.getElementById("info")){
		document.getElementById("info").innerHTML = "本窗口将在"+i+"秒后自动关闭";
	}
	if(i > 0)
		setTimeout("clock();",1000);
	else
		closewindow();
}

var i = 4;
clock();

</script>
</head>
<body>
<center>
	删除记录成功!<p>
	<div id="info">本窗口将在3秒后自动关闭</div>
	<input type="button" value="关闭窗口" onclick="closewindow();">
</center>
</body>
</html>

public_update_success.jsp文件:
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>更新记录成功</title>
<script type="text/javascript">
function closewindow(){
	if(window.opener){
		window.opener.location.reload(true);
		window.close();
	}
}
function clock(){
	i = i -1;
	if(document.getElementById("info")){
		document.getElementById("info").innerHTML = "本窗口将在"+i+"秒后自动关闭";
	}
	if(i > 0)
		setTimeout("clock();",1000);
	else
		closewindow();
}

var i = 4;
clock();

</script>
</head>
<body>
<center>
	更新记录成功!<p>
	<div id="info">本窗口将在3秒后自动关闭</div>
	<input type="button" value="关闭窗口" onclick="closewindow();">
</center>
</body>
</html>

update_add_succes.jsp文件
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>添加记录成功</title>
<script type="text/javascript">
function closewindow(){
	if(window.opener){
		window.opener.location.reload(true);
		window.close();
	}
}
function clock(){
	i = i -1;
	if(document.getElementById("info")){
		document.getElementById("info").innerHTML = "本窗口将在"+i+"秒后自动关闭";
	}
	if(i > 0)
		setTimeout("clock();",1000);
	else
		closewindow();
}

var i = 4;
clock();

</script>
</head>
<body>
<center>
	添加记录成功!<p>
	<div id="info">本窗口将在3秒后自动关闭</div>
	<input type="button" value="关闭窗口" onclick="closewindow();">
</center>
</body>
</html>

DelOrgAction.java文件
package com.oa.action;

import com.oa.manager.OrgManager;
import com.opensymphony.xwork2.ActionSupport;

public class DelOrgAction extends ActionSupport {
	private OrgManager orgManager;
	private int id;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setOrgManager(OrgManager orgManager) {
		this.orgManager = orgManager;
	}
	@Override
	public String execute() throws Exception {
		orgManager.deleteOrg(id);
		return "del_success";
	}
}

修改OrgManagerImpl.java的deleteOrg(int orgId)方法为:
    
 public void deleteOrg(int orgId) {
		Organization org = (Organization) getHibernateTemplate().load(Organization.class, orgId);
		if(org.getChildren().size() > 0)
			throw new RuntimeException("有子机构存在,不允许删除!");
		getHibernateTemplate().delete(getHibernateTemplate().load(Organization.class, orgId));
	}
修改index.jsp文件中
<a href="#" onclick="del('del.do?mentod=del&id=${org.id }');">删除</a></td>


<a href="#" onclick="del('del.action?id=${org.id }');">删除</a></td>

修改struts.xml文件为:
<package name="struts2" namespace="/" extends="struts-default">
        <global-results>
            <result name="add_success">/common/pub_add_success.jsp</result>
            <result name="del_success">/common/pub_del_success.jsp</result>
            <result name="update_success">/common/pub_update_success.jsp</result>
        </global-results>
        <action name="Login" class="loginAction">
            <result name="success">/result.jsp</result>
            <result name="input">/login.jsp</result>
        </action>
        
        <action name="org" class="orgAction">
            <result name="success">/org/index.jsp</result>
        </action>
        
        <action name="add_input" class="orgAction" method="add">
            <result name="success">/org/add_input.jsp</result>
        </action>
        
        <action name="add" class="addAction">
            <result name="success">/common/pub_add_success.jsp</result>
        </action>
        
        <action name="del" class="delAction"></action>
    </package>
applicationContext-actions.xml文件中添加:
   
<bean id="addAction" class="com.oa.action.AddOrgAction">
        <property name="orgManager" ref="orgManager"/>
    </bean>
    
    <bean id="delAction" class="com.oa.action.DelOrgAction">
        <property name="orgManager" ref="orgManager"/>
    </bean>


启动tomcat,测试!








你可能感兴趣的:(java,html,xml,jsp,log4j)