帝国CMS上传图片后不能返回正确文件名的解决办法
2012-12-25 22:15
776 查看
最近因为工作需要,要在java应用程序中打开一个网站,方法有多种,如通过Runtime.getRuntime().exec(""),但是这种方法关不掉session。
最后选择通过JNI来打开一个IE,ie在装载网页的办法,这种方法可以关掉session,下面我把代码贴出来,以供参考
struct EnumParam
{
HWND hMainWnd;
DWORD dwProcessID;
};
// 唯一的一个 CcjniApp 对象
CCjniApp theApp;
//HINSTANCE m_handle;
CString getIEpath();
//查找窗口句柄
BOOL CALLBACK EnumWinProc(HWND hwnd, LPARAM lParam)
{
DWORD dwID;
EnumParam* pep = (EnumParam*)lParam;
if (!(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE))
{
return TRUE;
}
GetWindowThreadProcessId(hwnd, &dwID);
if (dwID == pep->dwProcessID) {
pep->hMainWnd = hwnd;
return 0;
}
return TRUE;
}
DWORD myProcessID = 0;
HANDLE myProcessHandle;
JNIEXPORT jstring JNICALL Java_coc_jni_JniEx_showIE(JNIEnv *env, jobject obj,jstring str)
{
EnumParam ep;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ep.hMainWnd = NULL;
memset(&si, 0, sizeof(si));
si.cb = sizeof(STARTUPINFO);
jboolean isCopy=FALSE;
jsize len = (*env).GetStringLength(str);
const jchar *commandstr = (*env).GetStringChars(str,&isCopy);
const jchar *wndClassStr = NULL;
CString str1 = CString(commandstr);
(*env).ReleaseStringChars(str, commandstr);
if(str1.Find("close")!=-1)
{
::TerminateProcess(myProcessHandle,0);
myProcessID = 0;
myProcessHandle =NULL;
return NULL;
}
//strcpy((LPTSTR)&str1,(LPCTSTR)commandstr);
//int size = 0;
//size = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)commandstr, len, commandcstr,(len*2+1), NULL, NULL );
CString m_strPath = getIEpath();
CString path = m_strPath+" "+str1;
DWORD dwTick;
bool bCreateProcssFlag = true;
if(myProcessID!=0)
{
dwTick = GetTickCount();
ep.dwProcessID = myProcessID;
////查找窗口句柄
while(!ep.hMainWnd && GetTickCount()-dwTick<2000)
{
EnumWindows((WNDENUMPROC)EnumWinProc,
(long)&ep);
if(ep.hMainWnd==NULL)
Sleep(1000);
}
if(ep.hMainWnd!=NULL)
bCreateProcssFlag = false;
}
if (bCreateProcssFlag&&CreateProcess(NULL,path.GetBuffer(path.GetLength()),
NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
{
ep.dwProcessID = pi.dwProcessId;
myProcessID = pi.dwProcessId;
myProcessHandle = pi.hProcess;
dwTick = GetTickCount();
while(!ep.hMainWnd && GetTickCount()-dwTick<2000)
{
EnumWindows((WNDENUMPROC)EnumWinProc,
(long)&ep);
if(ep.hMainWnd==NULL)
Sleep(1000);
}
}
HWND hParent = ep.hMainWnd;
::ShowWindow(hParent,SW_RESTORE);
::SendMessage(hParent,WM_SHOWWINDOW,0,0);
::SetForegroundWindow(hParent);
return NULL;
}
//取得IE路径
CString getIEpath(){
HKEY hKEY;//定义有关的hKEY,在查询结束时要关闭
//打开与路径 data_Set相关的hKEY
LPCTSTR data_Set="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\iexplore.exe";
CString m_strPath;
//访问注册表,hKEY则保存此函数所打开的键的句柄
long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set,0,KEY_READ,&hKEY));
if(ret0!=ERROR_SUCCESS)//如果无法打开hKEY,则中止程序的执行
{
AfxMessageBox("error, can't open key!");
return "";
}
//查询有关的数据
LPBYTE path_Get=new BYTE[80];
DWORD type_1=REG_SZ;//定义数据类型
DWORD cbData_1=80;//定义数据长度
long ret1=::RegQueryValueEx(hKEY,"",NULL,&type_1,path_Get,&cbData_1);
if(ret1!=ERROR_SUCCESS)
{
AfxMessageBox("error, don't query key information!");
return "";
}
//显示信息
m_strPath=CString(path_Get);
delete[] path_Get;
//程序结束,关闭打开的hKEY
::RegCloseKey(hKEY);
return m_strPath;
}
最后选择通过JNI来打开一个IE,ie在装载网页的办法,这种方法可以关掉session,下面我把代码贴出来,以供参考
struct EnumParam
{
HWND hMainWnd;
DWORD dwProcessID;
};
// 唯一的一个 CcjniApp 对象
CCjniApp theApp;
//HINSTANCE m_handle;
CString getIEpath();
//查找窗口句柄
BOOL CALLBACK EnumWinProc(HWND hwnd, LPARAM lParam)
{
DWORD dwID;
EnumParam* pep = (EnumParam*)lParam;
if (!(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE))
{
return TRUE;
}
GetWindowThreadProcessId(hwnd, &dwID);
if (dwID == pep->dwProcessID) {
pep->hMainWnd = hwnd;
return 0;
}
return TRUE;
}
DWORD myProcessID = 0;
HANDLE myProcessHandle;
JNIEXPORT jstring JNICALL Java_coc_jni_JniEx_showIE(JNIEnv *env, jobject obj,jstring str)
{
EnumParam ep;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ep.hMainWnd = NULL;
memset(&si, 0, sizeof(si));
si.cb = sizeof(STARTUPINFO);
jboolean isCopy=FALSE;
jsize len = (*env).GetStringLength(str);
const jchar *commandstr = (*env).GetStringChars(str,&isCopy);
const jchar *wndClassStr = NULL;
CString str1 = CString(commandstr);
(*env).ReleaseStringChars(str, commandstr);
if(str1.Find("close")!=-1)
{
::TerminateProcess(myProcessHandle,0);
myProcessID = 0;
myProcessHandle =NULL;
return NULL;
}
//strcpy((LPTSTR)&str1,(LPCTSTR)commandstr);
//int size = 0;
//size = WideCharToMultiByte( CP_ACP, 0, (LPCWSTR)commandstr, len, commandcstr,(len*2+1), NULL, NULL );
CString m_strPath = getIEpath();
CString path = m_strPath+" "+str1;
DWORD dwTick;
bool bCreateProcssFlag = true;
if(myProcessID!=0)
{
dwTick = GetTickCount();
ep.dwProcessID = myProcessID;
////查找窗口句柄
while(!ep.hMainWnd && GetTickCount()-dwTick<2000)
{
EnumWindows((WNDENUMPROC)EnumWinProc,
(long)&ep);
if(ep.hMainWnd==NULL)
Sleep(1000);
}
if(ep.hMainWnd!=NULL)
bCreateProcssFlag = false;
}
if (bCreateProcssFlag&&CreateProcess(NULL,path.GetBuffer(path.GetLength()),
NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
{
ep.dwProcessID = pi.dwProcessId;
myProcessID = pi.dwProcessId;
myProcessHandle = pi.hProcess;
dwTick = GetTickCount();
while(!ep.hMainWnd && GetTickCount()-dwTick<2000)
{
EnumWindows((WNDENUMPROC)EnumWinProc,
(long)&ep);
if(ep.hMainWnd==NULL)
Sleep(1000);
}
}
HWND hParent = ep.hMainWnd;
::ShowWindow(hParent,SW_RESTORE);
::SendMessage(hParent,WM_SHOWWINDOW,0,0);
::SetForegroundWindow(hParent);
return NULL;
}
//取得IE路径
CString getIEpath(){
HKEY hKEY;//定义有关的hKEY,在查询结束时要关闭
//打开与路径 data_Set相关的hKEY
LPCTSTR data_Set="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\iexplore.exe";
CString m_strPath;
//访问注册表,hKEY则保存此函数所打开的键的句柄
long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set,0,KEY_READ,&hKEY));
if(ret0!=ERROR_SUCCESS)//如果无法打开hKEY,则中止程序的执行
{
AfxMessageBox("error, can't open key!");
return "";
}
//查询有关的数据
LPBYTE path_Get=new BYTE[80];
DWORD type_1=REG_SZ;//定义数据类型
DWORD cbData_1=80;//定义数据长度
long ret1=::RegQueryValueEx(hKEY,"",NULL,&type_1,path_Get,&cbData_1);
if(ret1!=ERROR_SUCCESS)
{
AfxMessageBox("error, don't query key information!");
return "";
}
//显示信息
m_strPath=CString(path_Get);
delete[] path_Get;
//程序结束,关闭打开的hKEY
::RegCloseKey(hKEY);
return m_strPath;
}
相关文章推荐
- string name = request.getParameter("name"); JAVA上传图片文件name返回空null解决办法
- codeigniter上传图片不能正确识别图片类型问题解决方法
- codeigniter上传图片不能正确识别图片类型问题解决方法
- ewebEditor不能上传文件图片等解决办法(.net)
- IE8不能上传、插入图片的解决办法!
- flash插件新版本导致shopex不能上传图片解决办法
- 图片在IE8及一下浏览器下不能正确显示的解决办法
- Jquery form.js文件上传返回JSON数据,在IE下提示下载文件的解决办法,并对返回数据进行正确的解析
- Windows 7下IE8不能上传图片解决办法
- 对于支持上传文件的手机浏览器出现的图片不能预览问题的解决办法
- Discuz!教程之论坛上传图片上传附件只能一个一个的添加不能批量上传的解决办法
- c# asp.net 使用kindeditor在服务器上不能显示上传图片的页面等解决办法
- ECSHOP后台编辑器不能上传中文名图片的解决办法
- 文本框后面的图片不能底对齐的解决办法
- 百度ueditor图片上传提示“上传失败,请重试”解决办法
- 关于JFinal的单个input标签type=file的multiple="multiple"多图片上传,每次只接收到一个uploadFile对象的解决办法。
- Android图片上传(看了别人的博客,图片无法上传,文章解决办法)
- 记录java上传图片第一时间无法展示的问题以及解决办法
- jquery+ajaxc回调函数内使用$(this)并不能正确找到对象的解决办法
- Serv-U中文文件名或路径 无法上传与下载的解决办法