sv_installcomplete.jsp 3.85 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
<%@page contentType="application/html;  charset=UTF-8;" pageEncoding="UTF-8"  %>

<%@page import="com.csc.library.utilities.*,com.csc.library.database.DataSet,java.util.*,com.csc.library.utilities.ThaiUtilities" %>
<%@page import="com.csc.library.database.CscConnection" %>
<%@page import="com.sun.org.apache.xerces.internal.impl.dv.util.Base64" %>
<%@page import="java.io.IOException" %>
<%@page import="java.io.InputStream" %>
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<%@page import="org.apache.commons.fileupload.FileItemFactory" %>
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %>
<%@page import="org.apache.commons.fileupload.FileItem" %>
<%@page import="com.google.gson.Gson" %>
<%@page import="com.google.gson.GsonBuilder" %>
<%@page import="com.google.gson.reflect.TypeToken" %>
<%@page import="com.csc.library.utility.MsgPackage" %>
<%@page import="com.csc.library.session.*" %>
<%@page import="com.csc.library.utility.MplsTimelog" %>

<%
		GsonBuilder gson = new GsonBuilder();
		Gson gs = gson.serializeNulls().create();

		UProfile up = new UProfile(); 
		up.setDbName("DBSYS");
		up.setSchemaName("dbo");
		up.setUserName("MYHRADMIN");
		up.set("companyid", "100");
		up.set("employeeid", "1262");
		up.set("lang", "eng");
		up.set("appname", "ANDROID");

		MsgPackage rtnmsg = new MsgPackage();
		MsgPackage mypck = new MsgPackage();

		try {

			System.out.print("/**************************************/");
			System.out.print("set up authen page has been called from client");

			boolean isMultipart = ServletFileUpload.isMultipartContent(request);

			if(isMultipart){
				System.out.print("!! Multipart data detected !!");
				// Create a factory for disk-based file items
				FileItemFactory factory = new DiskFileItemFactory();

				// Create a new file upload handler
				ServletFileUpload upload = new ServletFileUpload(factory);
				// Parse the request
				List /* FileItem */ items = upload.parseRequest(request);

				// Process the uploaded items
				Iterator iter = items.iterator();
				HashMap dataitem = new HashMap();
				long curtime = System.currentTimeMillis();
				while (iter.hasNext()) {
					FileItem item = (FileItem) iter.next();
					if (item.isFormField()) {
						String name = item.getFieldName();
						String value = item.getString();
						dataitem.put(name, value);
						System.out.print("!! Field name : "+ name + " value " + value);
					} else {
						System.out.print("!! File upload detected !!");
						/*
						String fieldName = item.getFieldName();
						String fileName = item.getName();
						String contentType = item.getContentType();
						boolean isInMemory = item.isInMemory();
						long sizeInBytes = item.getSize();
						String path = "D:/EnterprisePT/myHRAppServer/webapps/CSC/hrAppWeb.war/UPLOAD/REGISFP/PICTURES/" ;
						//File uploadedFile = new File(path + ((String) dataitem.get("empid")) + ".dat");
						File uploadedFile = new File(path + curtime + ".dat");
						dataitem.put("filepath", uploadedFile.getAbsolutePath());
						System.out.print("!! Absolute path -> " + uploadedFile.getAbsolutePath());
						item.write(uploadedFile);
						*/
					}
				}

				/* send receive msg to servr */
				if(dataitem.containsKey("data")){

					String rawtimedata = (String) dataitem.get("data");
					mypck = rtnmsg.convStrToMsgPackage(rawtimedata);
					/* use mypck to save into db */

					if(mypck.getComcode().equals("9")){
						if(mypck.getDatServe().equals("http://192.168.1.214")){
							mypck.setSetupAuthenStatus(true);
							mypck.setMessage("authen user successful.");
						}else{
							mypck.setSetupAuthenStatus(false);
							mypck.setMessage("authen user failed with incorrect server url");
						}
					}else{
						rtnmsg.status = "1";
						rtnmsg.msg = "authen user failed";
					}
				}
			}
		} catch(Exception e){
			e.printStackTrace();
		}

		out.print(mypck.getPackage());
%>