⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menuhandle.java

📁 j2ee权限验证
💻 JAVA
字号:
package com.gemt.privilege.struts;

import java.io.UnsupportedEncodingException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class MenuHandle extends DispatchAction {
	public ActionForward viewmenu(
		      ActionMapping mapping, ActionForm form, HttpServletRequest request,
		      HttpServletResponse response) throws Exception {
		try {
			final String sql = "select a.*,level from wpv0101_menu a "
				 +" start with id=100 "
				 +" connect by prior id = pmenuid "
				 +" group by pmenuid,level, id, msrtno, menunm, location, actiontyp, hlpid, lfabl "
				 +" order by id||'0', msrtno";
			java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
			java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.16:1521:szwrb", "szdba", "szwrb");
			java.sql.PreparedStatement pstmt = con.prepareStatement(sql);
			java.sql.ResultSet rs = pstmt.executeQuery();
			String xmlString = "";
			//StringBuffer sb = new StringBuffer();
			//final String XMLHEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><menu>"; 
			//final String XMLFOOTER = "</menu>";
			//long privousLevel = 1;
			String url = "";
			String menunm = "";
			
			DynaProperty[] props = new DynaProperty[]{
			        //new DynaProperty("address", java.util.Map.class),
			       // new DynaProperty("subordinate", mypackage.Employee[].class),
			        new DynaProperty("menunm", String.class),
			        new DynaProperty("menunmurl", String.class),
			        new DynaProperty("level",  Long.class),
			        new DynaProperty("id",  Long.class),
			        new DynaProperty("pmenuid",  Long.class),
			        new DynaProperty("msrtno",  Long.class),
			        new DynaProperty("actiontyp",  Long.class),
			        new DynaProperty("location", String.class)//,
			        //new DynaProperty("menunm", String.class),
			        //new DynaProperty("menunm", String.class)
			      };
			BasicDynaClass dynaClass = new BasicDynaClass("employee", null, props);
			Collection<DynaBean> col = new ArrayList<DynaBean>();

			while(rs.next()) {
				try {
					if(rs.getString("location") != null && !"".equals(rs.getString("location").trim()));
						url = java.net.URLEncoder.encode(rs.getString("location"),"UTF-8");
					//menunm = java.net.URLEncoder.encode(rs.getString("menunm"), "UTF-8");
				}
				catch(Exception ex) {
					//ex.printStackTrace();
				}
				
				try {
					menunm = java.net.URLEncoder.encode(rs.getString("menunm"), "UTF-8");
				} catch (UnsupportedEncodingException ue) {
					// TODO Auto-generated catch block
					ue.printStackTrace();
				}
				long pid = (rs.getLong("pmenuid")==0)?-1:rs.getLong("pmenuid");
				xmlString +="d.add("+ rs.getLong("id") + "," + pid +",'" + rs.getString("menunm") + "','menuhandle.do?method=edit&level="+ rs.getLong("level") +"&id=" + rs.getLong("id") +"&pmenuid=" + pid + "&menunm=" + menunm + "&location=" + url + "','','privilege');\n";
				
				DynaBean menuItem = dynaClass.newInstance();
			    //employee.set("address", new HashMap());
			    //employee.set("subordinate", new mypackage.Employee[0]);
				menuItem.set("menunm", rs.getString("menunm"));
				menuItem.set("menunmurl", menunm);
				menuItem.set("level", rs.getLong("level"));
				menuItem.set("id", rs.getLong("id"));
				menuItem.set("pmenuid", pid);
				menuItem.set("msrtno", rs.getLong("msrtno"));
				menuItem.set("actiontyp", rs.getLong("actiontyp"));
				menuItem.set("level", rs.getLong("level"));
				menuItem.set("location", url);
				
				col.add(menuItem);
				/*
				if(rs.getLong("level") == 1) {
					privousLevel = rs.getLong("level");
					sb.append("<menutree>");
					sb.append("<level>" + rs.getLong("level") + "</level>");
					sb.append("<pmenuid>" + rs.getLong("pmenuid") + "</pmenuid>");
					sb.append("<id>" + rs.getLong("id") + "</id>");
					sb.append("<msrtno>" + rs.getLong("msrtno") + "</msrtno>");
					sb.append("<menunm>" + rs.getLong("menunm") + "</menunm>");
					sb.append("<location>" + rs.getLong("location") + "</location>");
					sb.append("<actiontyp>" + rs.getLong("actiontyp") + "</actiontyp>");
					sb.append("<hlpid>" + rs.getLong("hlpid") + "</hlpid>");
					sb.append("<lfabl>" + rs.getLong("lfabl") + "</lfabl>");
					sb.append("</menutree>");
				}
				if(rs.getLong("level") == privousLevel) {
					
				}
				else if(rs.getLong("level") < privousLevel){
					
				}
				else if(rs.getLong("level") > privousLevel){
					
				}
				*/
				url = "";
				menunm = "";
			}
			
			if(rs != null) rs.close();
			if(pstmt != null) pstmt.close();
			if(con != null) con.close();
			
			
			//System.out.println("" + xmlString);
			MenuHandleForm menuHandleForm = (MenuHandleForm) form;
			menuHandleForm.setTreeCol(col);
			menuHandleForm.setTreeString(xmlString);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return mapping.findForward("viewmenu");
	}
	
	public ActionForward view(
		      ActionMapping mapping, ActionForm form, HttpServletRequest request,
		      HttpServletResponse response) throws Exception {
		return mapping.findForward("view");
	}
	
	public ActionForward save(
		      ActionMapping mapping, ActionForm form, HttpServletRequest request,
		      HttpServletResponse response) throws Exception {
		final String sql = "update wpv0101_menu set msrtno=?, menunm=?, location=?, actiontyp=? where id=?";
		java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
		java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.16:1521:szwrb", "szdba", "szwrb");
		java.sql.PreparedStatement pstmt = con.prepareStatement(sql);
		MenuHandleForm menuHandleForm = (MenuHandleForm) form;
		long msrtno = menuHandleForm.getMsrtno()==null?0:menuHandleForm.getMsrtno().longValue();
		long actiontyp = menuHandleForm.getActiontyp()==null?0:menuHandleForm.getActiontyp().longValue();
		long id = menuHandleForm.getId()==null?0:menuHandleForm.getId().longValue();
		pstmt.setLong(1, msrtno);
		pstmt.setString(2, menuHandleForm.getMenunm());
		System.out.println("menu name = " + menuHandleForm.getMenunm());
		pstmt.setString(3, menuHandleForm.getLocation());
		System.out.println("actiontyp = " + actiontyp);
		pstmt.setLong(4, actiontyp);
		pstmt.setLong(5, id);
		System.out.println("id = " + menuHandleForm.getId());
		pstmt.executeUpdate();
		con.commit();
		if(pstmt != null) pstmt.close();
		if(con != null) con.close();
		
		return mapping.findForward("success");
	}
	
	public ActionForward delmenu(
		      ActionMapping mapping, ActionForm form, HttpServletRequest request,
		      HttpServletResponse response) throws Exception {
		final String sql = "delete from wpv0101_menu where id in (select a.id from wpv0101_menu a start with id=? connect by prior id = pmenuid )";
		java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
		java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.16:1521:szwrb", "szdba", "szwrb");
		java.sql.PreparedStatement pstmt = con.prepareStatement(sql);
		MenuHandleForm menuHandleForm = (MenuHandleForm) form;
		//long msrtno = menuHandleForm.getMsrtno()==null?0:menuHandleForm.getMsrtno().longValue();
		//long actiontyp = menuHandleForm.getActiontyp()==null?0:menuHandleForm.getActiontyp().longValue();
		long id = menuHandleForm.getId()==null?0:menuHandleForm.getId().longValue();
		//long pmenuid = menuHandleForm.getPmenuid()==null?0:menuHandleForm.getPmenuid().longValue();
		//long level = menuHandleForm.getLevel()==null?0:menuHandleForm.getLevel().longValue();
		pstmt.setLong(1, id);

		System.out.println("id = " + menuHandleForm.getId());
		pstmt.executeUpdate();
		con.commit();
		if(pstmt != null) pstmt.close();
		if(con != null) con.close();		
		return mapping.findForward("success");
	}
	
	public ActionForward edit(
		      ActionMapping mapping, ActionForm form, HttpServletRequest request,
		      HttpServletResponse response) throws Exception {
		System.out.println("edit");
		return mapping.findForward("edit");
	}
	
	public ActionForward addMenu(
		      ActionMapping mapping, ActionForm form, HttpServletRequest request,
		      HttpServletResponse response) throws Exception {
		
		final String sql1 = "insert into  wpv0101_menu(id,menunm,location,msrtno,pmenuid,lfabl,hlpid, actiontyp) values((select max(id)+1 from wpv0101_menu where pmenuid is null),?,?,nvl((select max(msrtno) from wpv0101_menu where pmenuid is null),1),?,0,null,0)";
		final String sql2 = "insert into  wpv0101_menu(id,menunm,location,msrtno,pmenuid,lfabl,hlpid, actiontyp) values((select max(id)+1 from wpv0101_menu where pmenuid=?),?,?,nvl((select max(msrtno) from wpv0101_menu where pmenuid=?),1),?,?,null,?)";
		java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
		java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.16:1521:szwrb", "szdba", "szwrb");
		PreparedStatement pstmt = null;
		MenuHandleForm menuHandleForm = (MenuHandleForm) form;
		//long msrtno = menuHandleForm.getMsrtno()==null?0:menuHandleForm.getMsrtno().longValue();
		
		long actiontyp = menuHandleForm.getActiontyp()==null?0:menuHandleForm.getActiontyp().longValue();
		long id = menuHandleForm.getId()==null?0:menuHandleForm.getId().longValue();
		long pmenuid = menuHandleForm.getPmenuid()==null?0:menuHandleForm.getPmenuid().longValue();
		long level = menuHandleForm.getLevel()==null?0:menuHandleForm.getLevel().longValue();
		if(level == 1) {
			pstmt = con.prepareStatement(sql1);
			//pstmt.setLong(1, id);
			//pstmt.setLong(2, id);
			pstmt.setString(1, menuHandleForm.getMenunm());
			System.out.println("menu name = " + menuHandleForm.getMenunm());
			pstmt.setString(2, menuHandleForm.getLocation());
			System.out.println("actiontyp = " + actiontyp);
			pstmt.setLong(3, pmenuid);
			//pstmt.setLong(6, id);
			//pstmt.setLong(7, level<3?0:1);
			//pstmt.setLong(8, actiontyp);
		}
		else {
			pstmt = con.prepareStatement(sql2);
			pstmt.setLong(1, pmenuid);
			pstmt.setString(2, menuHandleForm.getMenunm());
			System.out.println("menu name = " + menuHandleForm.getMenunm());
			pstmt.setString(3, menuHandleForm.getLocation());
			System.out.println("actiontyp = " + actiontyp);
			pstmt.setLong(4, pmenuid);
			pstmt.setLong(5, pmenuid);
			pstmt.setLong(6, level<3?0:1);
			pstmt.setLong(7, actiontyp);			
		}
		System.out.println("id = " + menuHandleForm.getId());
		pstmt.executeUpdate();
		con.commit();
		if(pstmt != null) pstmt.close();
		if(con != null) con.close();		
		return mapping.findForward("success");
	}
	
	public ActionForward addSubmenu(
		      ActionMapping mapping, ActionForm form, HttpServletRequest request,
		      HttpServletResponse response) throws Exception {
		final String sql = "insert into  wpv0101_menu(id,menunm,location,msrtno,pmenuid,lfabl,hlpid, actiontyp) values(nvl((select max(id)+1 from wpv0101_menu where pmenuid=?), ?*100+1),?,?,nvl((select max(msrtno)+1 from wpv0101_menu where pmenuid=?),1),?,?,null,?)";
		java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
		java.sql.Connection con = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.16:1521:szwrb", "szdba", "szwrb");
		java.sql.PreparedStatement pstmt = con.prepareStatement(sql);
		MenuHandleForm menuHandleForm = (MenuHandleForm) form;
		//long msrtno = menuHandleForm.getMsrtno()==null?0:menuHandleForm.getMsrtno().longValue();
		long actiontyp = menuHandleForm.getActiontyp()==null?0:menuHandleForm.getActiontyp().longValue();
		long id = menuHandleForm.getId()==null?0:menuHandleForm.getId().longValue();
		//long pmenuid = menuHandleForm.getPmenuid()==null?0:menuHandleForm.getPmenuid().longValue();
		long level = menuHandleForm.getLevel()==null?0:menuHandleForm.getLevel().longValue();
		pstmt.setLong(1, id);
		pstmt.setLong(2, id);
		pstmt.setString(3, menuHandleForm.getMenunm());
		System.out.println("menu name = " + menuHandleForm.getMenunm());
		pstmt.setString(4, menuHandleForm.getLocation());
		System.out.println("actiontyp = " + actiontyp);
		pstmt.setLong(5, id);
		pstmt.setLong(6, id);
		pstmt.setLong(7, level<3?0:1);
		pstmt.setLong(8, actiontyp);
		System.out.println("id = " + menuHandleForm.getId());
		pstmt.executeUpdate();
		con.commit();
		if(pstmt != null) pstmt.close();
		if(con != null) con.close();
		
		return mapping.findForward("success");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -