📄 commondata.java
字号:
package com.base;
import java.lang.Integer;
import java.util.Vector;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Enumeration;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import com.erpbase.general.Log;
import com.erpbase.util.Form;
import com.erpbase.util.StringUtility;
import com.erpbase.bl.basemodules.usersession.UserSessionData;
public class CommonData
{
private String _processInfo;
private HttpServletRequest _request; //私有变量,存放来自客户端的request请求。
private HttpSession _session; //存放用户的session信息
private UserSessionData _userData; //用户的session信息
private int iValuesLength = 0; //私有变量,存放字段数组长度。
private HashMap allValuesMap; //私有变量,初始化时存放从页面获得的所有值。
/**
* 功能:初始化信息,获得页面提交给主控制器的请求信息。
* @param request:客户端向服务器端的请求信息。
*/
public void init( HttpServletRequest request, HttpSession session)
throws SysException
{
_request = request;
_session = session;
_userData = (UserSessionData)session.getAttribute("usersession");
if(_userData == null) throw new SysException("用户的session标识错误,不是usersession");
setAllRequestValues();
}
/**
* 功能:设置processInfo信息。
*/
public void setProcessInfo(String strProcessInfo)
{
_processInfo = strProcessInfo;
}
/**
* 功能:得到processInfo信息。
*/
public String getProcessInfo()
{
return _processInfo;
}
/**
* 功能:获得提交页面所有的数据,存放到allValuesMap中。
*/
private void setAllRequestValues()
{
allValuesMap = new HashMap();
Enumeration enm = _request.getParameterNames();
Form.setRequest(_request);
while( enm.hasMoreElements())
{
String strFieldName = (String)enm.nextElement();
String[] strValues = Form.gets(strFieldName);
allValuesMap.put(strFieldName,strValues);
}
}
/**
* 功能:从session中取出对象
* @param strKey:对象标识
* @return obj :存放的对象
*/
public Object getSessionAttribute(String strKey)
{
return _session.getAttribute(strKey);
}
/**
* 功能:获得提交页面request请求。
*/
public HttpServletRequest getRequest()
{
return _request;
}
/**
* 功能:向request中放置对象,这个方法封装了reqest对象的
* setAttribute()方法。
* @param strKey:键值,通过此键值获得存放的对象
* @param obj:存放的Object对象。
*/
public void setAttribute( String strKey,Object obj)
{
_request.setAttribute( strKey,obj);
}
/**
* 功能:设置页面提交后的返回参数,主控制器执行完成后转向到
* 操作结果提示页后,此值作为返回时的参数。
* @param strParameter:返回参数(即"?"后面的参数部分)
*/
public void setReturnParameter( String strParameter)
{
_request.setAttribute("_returnParameter",strParameter);
}
/**
* 功能:设置页面提交后的返回JSP路径,主控制器执行完成后转向
* 此页面。
* @param strJspPath:返回JSP页面
* @param bIsRedirectTurnto:是否直接返回,true表示直接返回,false表示
* 先提交到结果提示页面后再返回。
*/
public void setReturnJspPath(String strJspPath, boolean bIsRedirectTurnto)
{
String strIsRedirectTurnTo = "";
if(bIsRedirectTurnto)
strIsRedirectTurnTo = "Y";
else
strIsRedirectTurnTo = "N";
_request.setAttribute("_returnJspPath", strJspPath);
_request.setAttribute("_returnType",strIsRedirectTurnTo);
}
/**
* 功能:获得页面请求信息的名称。
* @return vctFieldName:页面请求信息名称。
*/
public Vector getFieldNames()
{
Vector vctFieldName = new Vector();
Enumeration enm = _request.getParameterNames();
while( enm.hasMoreElements())
{
vctFieldName.add( enm.nextElement());
}
return vctFieldName;
}
/**
*功能:获得页面的所有的请求信息的名称
*说明:其中返回的Map中的key值为名称的小写,Value的值为名称的实际书写方式
*/
public HashMap getFieldMap()
{
HashMap mapField = new HashMap();
Enumeration enm = _request.getParameterNames();
while( enm.hasMoreElements())
{
String strField = (String)enm.nextElement();
String strValue = strField;
mapField.put(strField.toLowerCase(), strValue);
}
return mapField;
}
/**
* 功能:获得提交页面某一组件名称对应的值。
* @param strFieldName:提交页面组件名称
* @return strFieldValue:组件对应值
*/
public String getValue( String strFieldName)
{
String[] strValues = (String[])allValuesMap.get(strFieldName);
if(strValues!=null && strValues.length>0)
return strValues[0];
else
return "";
}
/**
* 功能:获得提交页面某一组件名称对应的值。
* @param strFieldName:提交页面组件名称
* @return strFieldValue:组件对应值
*/
public String[] getValues(String strFieldName)
{
return (String[])allValuesMap.get(strFieldName);
}
/**
*功能:从前台得到需要的有重复的field对象的值
*说明:
@param mapFields中的value为页面中的fields对象
*/
public HashMap getValues(HashMap mapFields)
{
HashMap mapTemp = new HashMap();
HashMap mapValues = new HashMap();
Iterator iterFieldNames = (mapFields.keySet()).iterator();
int iMaxValuesLen = 0;
while(iterFieldNames.hasNext())
{
String strKey = (String)iterFieldNames.next();
String strFieldName = (String)mapFields.get(strKey);
String[] strValues = getValues(strFieldName);
if(strValues != null && strValues.length>0)
{
mapTemp.put(strKey, strValues);
if(strValues.length>iMaxValuesLen)iMaxValuesLen = strValues.length;
Log.printDebug("&&&&&&&&& strFieldName="+strFieldName+" || iMaxValuesLen="+strValues.length+" &&&&&&&&&&");
}
}
if(iMaxValuesLen>1)
{
Iterator iterValues = mapTemp.keySet().iterator();
while(iterValues.hasNext())
{
String strKey = (String)iterValues.next();
String[] strValues = (String[])mapTemp.get(strKey);
if(strValues!=null && strValues.length==iMaxValuesLen)
{
mapValues.put(strKey,strValues);
}
}
}
else
{
mapValues = mapTemp;
}
iValuesLength = iMaxValuesLen;
return mapValues;
}
/**
*功能:得到页面数据数组的长度
*/
public int getValuesLength()
{
return iValuesLength;
}
/**
* 功能:获得操作人所属的企业编码
*/
public String getCor_code()
{
Log.printDebug("------------------------------" + _userData.get("cor_code"));
return _userData.get("cor_code");
}
/**
* 功能:获得操作人的编码
*/
public String getEmp_code()
{
return _userData.get("emp_code");
}
/**
* 功能:获得操作人所属的编码
*/
public String getDep_code()
{
return _userData.get("dep_code");
}
/**
* 功能:获得当前的菜单编码
*/
public String getMenuCode()
{
return StringUtility.dispose((String)_session.getAttribute("menu"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -