functag.java~2~

来自「采用web2.0技术,采用动态标签,sql语句全部存储在数据库里面.开发速度快.」· JAVA~2~ 代码 · 共 259 行

JAVA~2~
259
字号
package com.sztheater.web.taglib;
import java.text.DateFormat;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
import com.sztheater.framework.util.*;
public class FuncTag{

        public static Object getObject(Object objValue,String s_item) {
                int     iPos = 0;
                String  para_name  = null;
                String  class_name = null;
                Object  vObj       = null;
                int     iIndex     = 0;
                int     iSize      = 0;
                boolean bFind      = false;
                boolean bExists    = false;
                if(objValue==null || s_item ==null ) return objValue;
                s_item = s_item.trim();
                if(s_item.trim().equals("")) return objValue;

                class_name = objValue.getClass().getName();
                if(class_name.equals("java.lang.String")) return objValue;

                vObj    = null;
                iPos    = s_item.indexOf(".");
                if(iPos>-1){
                        para_name = s_item.substring(0    , iPos);
                        s_item    = s_item.substring(iPos + 1);
                }else{
                        para_name = s_item;
                        s_item    = "";
                }
                if(class_name.indexOf("HttpServletRequest")>-1){
                        HttpServletRequest request = (HttpServletRequest)objValue;
                        vObj   = request.getAttribute(para_name);
                        if(vObj==null) vObj  = request.getParameter(para_name);
                        if(s_item.equals("")) return vObj;
                        bFind = true;
                }
                if(class_name.indexOf("PageContextImpl")>-1){
                        PageContext pc = (PageContext)objValue;
                        vObj   = pc.getRequest().getAttribute(para_name);
                        if(vObj==null) vObj  = pc.getRequest().getParameter(para_name);
                        if(s_item.equals("")) return vObj;
                        bFind = true;
                }
                if(class_name.equals("com.ezihao.framework.util.ValueObject")){
                        ValueObject valueObj = (ValueObject)objValue;
                        if(para_name.equals("func_id")){
                                return 	valueObj.getFuncID();
                        }
                        if(para_name.equals("action_id")){
                                return 	valueObj.getActionID();
                        }
                        vObj  = null;
                        if(para_name.equals("page")){
                                vObj    = valueObj.getPage();
                                bExists = true;
                        }
                        if(para_name.equals("dataset")){
                                vObj  = valueObj.getResultSet();
                                bExists = true;
                        }
                        if(para_name.equals("param")){
                                vObj  = valueObj.getParam();
                                bExists = true;
                        }
                        if(para_name.equals("user")){
                                vObj  = valueObj.getUser();
                                bExists = true;
                        }
                        if(para_name.equals("message")){
                                vObj  = valueObj.getMessage();
                                bExists = true;
                        }
                        if(para_name.equals("exception")){
                                vObj  = valueObj.getException();
                                bExists = true;
                        }
                        if(para_name.equals("trace")){
                                vObj  = valueObj.getTrace();
                                bExists = true;
                        }
                        bFind = true;
                        if(s_item.equals("")) return vObj;
                }
                if(class_name.equals("java.util.ArrayList")){
                        ArrayList aList = (ArrayList)objValue;
                        iSize  = aList.size();
                        iIndex = 0;
                        try{
                                iIndex = Integer.parseInt(para_name);
                        }catch(Exception e){

                        }
                        if(iSize<1 || iIndex<0 || iIndex>=iSize) return null;
                        vObj  = aList.get(iIndex);
                        bFind = true;
                        if(s_item.equals("")) return vObj;
                }
                if(class_name.equals("java.util.HashMap")){
                        HashMap aHash = (HashMap)objValue;
                        iSize  = aHash.size();
                        if(iSize<1) return null;
                        vObj  = aHash.get(para_name);
                        System.out.println(para_name+"="+vObj);
                        bFind = true;
                        if(s_item.equals("")) return vObj;
                }
                if(class_name.equals("java.util.Hashtable")){
                        Hashtable bHash = (Hashtable)objValue;
                        iSize  = bHash.size();
                        if(iSize<1) return null;
                        vObj  = bHash.get(para_name);
                        bFind = true;
                        if(s_item.equals("")) return vObj;
                }
                if(!bFind) return null;
                return getObject(vObj,s_item);
        }
        /**
        * 通过取得下拉框的HTML代码
        * @param aList      ArrayList   数据列表
        * @param value      String      当前下拉的值
        * @param EmptyValue String      为空的时候的值
        * @param f_value    String      真实值字段名
        * @param f_disp     String      显示值字段名
        * @param bMerge     boolean     合并标志
        */
        public static String getComboboxHTML(ArrayList aList,String value,String EmptyValue,String f_value,String f_disp,boolean bMerge){
                //入参检验
                if(f_disp ==null || f_disp.trim().equals ("")) return "";
                if(f_value==null || f_value.trim().equals("")) return "";
                f_value = f_value.trim();
                f_disp  = f_disp.trim ();

                StringBuffer sbHTML = new StringBuffer("");
                String   strHTML  = "";
                int      iLoop    = 0 ;
                int      iLoopNum = 0;
                HashMap  aHash    = null;
                Object   obj      = null;
                if(EmptyValue!=null) sbHTML.append("<option value=''>"+EmptyValue+"</option>\n");
                if(aList!=null) iLoopNum = aList.size();
                String s_disp  = null;
                String s_value = null;
                for(iLoop=0;iLoop<iLoopNum;iLoop++){
                        obj   = aList.get(iLoop);
                        if(obj==null || !obj.getClass().getName().equals("java.util.HashMap")) continue;
                        aHash   = (HashMap) obj;
                        s_disp  = (String)aHash.get(f_disp);
                        s_value = (String)aHash.get(f_value);
                        if(s_value==null) continue;
                        if(s_disp ==null) s_disp = "";
                        sbHTML.append("<option value=\""+s_value+"\" ");
                        Iterator it = aHash.keySet().iterator();
                        while(it!=null && it.hasNext()){
                                String keyObj  = (String)it.next();
                                String valueObj= (String)aHash.get(keyObj);
                                if(keyObj==null || valueObj==null || keyObj.equals("ROW_ID"))continue;
                                if(keyObj.equals(f_disp) || keyObj.equals(f_value)) continue;
                                sbHTML.append( keyObj +" = \"" + valueObj + "\"");
                        }
                        if(s_value.equals(value) || s_disp.equals(value)) sbHTML.append(" selected ");
                        if(bMerge) s_disp = s_value+" "+s_disp;
                        sbHTML.append(" >"+s_disp+"</option>\n");
                }
                strHTML = sbHTML.toString();
                sbHTML.delete(0,sbHTML.length());
                sbHTML = null;
                return strHTML;
        }
        /**
        * 通过服务来取得下拉列表的数据信息
        * @param pc         PageContext 标签基本属性
        * @param action     String      服务名称
        * @param servType   String      服务类型
        * @param formerPara String      前置参数
        */
        public static ArrayList getStaticItems(PageContext pc,String func_id, String action,HashMap hashCond,boolean bTrace){
                if( func_id==null || func_id.trim().equals("")) return null;
                if( action ==null || action.trim().equals ("")) action = "select";
                int       iSuccFlag = 0;

                HttpSession  httpSession  = null;
                ValueObject  recvPack  = new ValueObject();
                ValueObject  sendPack  = new ValueObject();
                String    data_set   = "data_list";
                HashMap   hashUser   = null;
                Object    obj        = null;
                try{
                        sendPack.setFuncID  (func_id  );
                        sendPack.setActionID(action   );
                        if(hashCond!=null && hashCond.size()>0){
                                recvPack.putParam(hashCond);
                        }
                        //用户信息
                        httpSession = pc.getSession();
                        obj = httpSession.getAttribute("userinfo");
                        if(obj!=null && obj.getClass().getName().equals("java.util.HashMap")) {
                                hashUser = (HashMap)obj;
                                sendPack.setUser(hashUser);
                        }


                        if(bTrace) recvPack.setTrace(true);
                        //执行数据库中对应的SQL语句
//			iSuccFlag = SysCall.execute(null,sendPack,recvPack);

                        if(iSuccFlag<0) {
                                System.out.println(sendPack.getMessage());
                                return null;
                        }
                        data_set = func_id.trim().toLowerCase();
                        if( func_id.equals("DICT") || action.equals("psql")) data_set  = "data_list";
                        return  recvPack.getDataSet(data_set);
                }catch(Exception e){
                        System.out.println("取得静态字典异常:"+e.getMessage());
                }finally{
                        sendPack.free();
                        recvPack.free();
                        sendPack = null;
                        recvPack = null;
                }
                return null;
        }
        public static HashMap getValues(String str){
                if(str==null) return null;
                HashMap aHash = null;
                int       iPos1  = 0;
                int       iPos   = 0;
                String    f_name = null;
                String    f_value=null;
                str = "`" + str;
                while(!str.equals("")){
                        iPos  = str.indexOf("`");
                        if(iPos<0) {
                                f_name = str;
                                str    = "";
                        }else{
                                f_name = str.substring(0,iPos);
                                str    = str.substring( iPos+1 );
                        }
                        iPos   = f_name.indexOf("=");
                        if(iPos<0 || f_name.trim().equals("")) continue;

                        f_value= f_name.substring(iPos+1);
                        f_name = f_name.substring(0,iPos);
                        f_name = f_name.trim().toLowerCase();
                        if(aHash==null) aHash = new HashMap();
                        aHash.put(f_name , f_value);
                }
                return aHash;
        }
}

⌨️ 快捷键说明

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