Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.03 KB | None | 0 0
  1. <%
  2. try{
  3. if(session.getAttribute("ses_uname").toString().length()==0){
  4. out.println("You are not Authorised User-try properly");
  5. //this.destroy();
  6. }
  7. }catch(Exception e){
  8. out.println("You are not Authorised User-try properly");%>
  9. <jsp:forward page="./index.jsp"/><%
  10.  
  11. }
  12.  
  13.  
  14.  
  15. %>
  16. <%
  17.  
  18. int mcole;
  19. String mcoleName=new String();
  20. String madd1=new String();
  21. String madd2=new String();
  22. String madd3=new String();
  23. String mColephone=new String();
  24. String mfax=new String();
  25. String memail=new String();
  26. String mdsnName=new String();
  27. String mimage=new String();
  28. String mdataUID=new String();
  29. String mdataPass=new String();
  30.  
  31. //mcole =Integer.parseInt(session.getAttribute("coleCode") );
  32. mcoleName= String.valueOf(session.getAttribute("coleName") );
  33. madd1= String.valueOf(session.getAttribute("add1")) ;
  34. madd2=String.valueOf( session.getAttribute("add2")) ;
  35. madd3= String.valueOf(session.getAttribute("add3")) ;
  36. mColephone= String.valueOf(session.getAttribute("phone")) ;
  37. mfax= String.valueOf(session.getAttribute("fax") );
  38. memail= String.valueOf(session.getAttribute("memail")) ;
  39. mdsnName=String.valueOf( session.getAttribute("dsnName")) ;
  40. mimage=String.valueOf(session.getAttribute("logo") );
  41.  
  42. %>
  43.  
  44. <%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
  45. <%@ page import="java.io.FileWriter,java.io.IOException" %>
  46. <%@page import ="java.util.Date,java.text.SimpleDateFormat"%>
  47. <%@ page import="java.io.*, java.lang.*" %>
  48. <%@ page import="java.sql.*" %>
  49. <%@page import ="java.util.Date"%>
  50. <%@ page import="org.apache.poi.hssf.usermodel.*"%>
  51.  
  52.  
  53. <P align=center style="color:#990000;"><FONT
  54. color="#990000" size=5><img src=<%=mimage%> border="0">
  55. <html>
  56. <head>
  57. <title>
  58. Examination Marks Entry / Modify
  59. </title>
  60. </head>
  61.  
  62. <body bgcolor="#dbe7fb">
  63.  
  64.  
  65. <p align="right" style="font-size:10pt;" ><a href="aerpLogOut.jsp">Log Out</a></p>
  66. <%
  67. String savePath = "", filepath = "", filename ="";
  68. String contentType = "", fileData = "", strLocalFileName = "";
  69. int startPos = 0, endPos = 0;
  70. int BOF = 0, EOF = 0;
  71. String fixfname="";
  72. %>
  73. <%!
  74. //copy specified number of bytes from main data buffer to temp data buffer
  75. void copyByte(byte [] fromBytes, byte [] toBytes, int start, int len)
  76. {
  77. for(int i=start;i<(start+len);i++)
  78. {
  79. toBytes[i - start] = fromBytes[i];
  80. }
  81. }
  82. %>
  83.  
  84. <%
  85. contentType = request.getContentType();
  86. // out.println("<br>Content type is :: " +contentType);
  87. if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0))
  88. {
  89. DataInputStream in = new DataInputStream(request.getInputStream());
  90. DataInputStream in1 = in;
  91. int formDataLength = request.getContentLength();
  92. //out.println(formDataLength);
  93. byte dataBytes[] = new byte[formDataLength];
  94. int byteRead = 0;
  95. int totalBytesRead = 0;
  96. while (totalBytesRead < formDataLength)
  97. {
  98. byteRead = in1.read(dataBytes, totalBytesRead, formDataLength);
  99. totalBytesRead += byteRead;
  100. }
  101. // out.println("<br>totalBytesRead : " + totalBytesRead + " : formDataLength = " + formDataLength);
  102.  
  103. // String file = new String(dataBytes);
  104. // out.println("<br>File Contents:<br>////////////////////////////////////<br>" + file + "<br>////////////////////////////////<br>");
  105.  
  106. byte[] line = new byte[128];
  107. if (totalBytesRead < 3)
  108. {
  109. return; //exit if file length is not sufficiently large
  110. }
  111.  
  112. String boundary = "";
  113. String s = "";
  114. int count = 0;
  115. int pos = 0;
  116.  
  117. //loop for extracting boundry of file
  118. //could also be extracted from request.getContentType()
  119. do
  120. {
  121. copyByte(dataBytes, line, count ,1); //read 1 byte at a time
  122. count+=1;
  123. s = new String(line, 0, 1);
  124. fileData = fileData + s;
  125. pos = fileData.indexOf("Content-Disposition: form-data; name=\""); //set the file name
  126. if(pos != -1)
  127. endPos = pos;
  128. }while(pos == -1);
  129. boundary = fileData.substring(startPos, endPos);
  130.  
  131. //loop for extracting filename
  132. startPos = endPos;
  133. do
  134. {
  135. copyByte(dataBytes, line, count ,1); //read 1 byte at a time
  136. count+=1;
  137. s = new String(line, 0, 1);
  138. fileData = fileData + s;
  139. pos = fileData.indexOf("filename=\"", startPos); //set the file name
  140. if(pos != -1)
  141. startPos = pos;
  142. }while(pos == -1);
  143. do
  144. {
  145. copyByte(dataBytes, line, count ,1); //read 1 byte at a time
  146. count+=1;
  147. s = new String(line, 0, 1);
  148. fileData = fileData + s;
  149. pos = fileData.indexOf("Content-Type: ", startPos);
  150. if(pos != -1)
  151. endPos = pos;
  152. }while(pos == -1);
  153. filename = fileData.substring(startPos + 10, endPos - 3); //to eliminate " from start & end
  154. fixfname=filename;
  155. strLocalFileName = filename;
  156. int index = filename.lastIndexOf("\\");
  157. if(index != -1)
  158. filename = filename.substring(index + 1);
  159. else
  160. filename = filename;
  161.  
  162. //loop for extracting ContentType
  163. boolean blnNewlnFlag = false;
  164. startPos = endPos; //added length of "Content-Type: "
  165. do
  166. {
  167. copyByte(dataBytes, line, count ,1); //read 1 byte at a time
  168. count+=1;
  169. s = new String(line, 0, 1);
  170. fileData = fileData + s;
  171. pos = fileData.indexOf("\n", startPos);
  172. if(pos != -1)
  173. {
  174. if(blnNewlnFlag == true)
  175. endPos = pos;
  176. else
  177. {
  178. blnNewlnFlag = true;
  179. pos = -1;
  180. }
  181. }
  182. }while(pos == -1);
  183. contentType = fileData.substring(startPos + 14, endPos);
  184.  
  185. //loop for extracting actual file data (any type of file)
  186. BOF = count + 1;
  187.  
  188. do
  189. {
  190. copyByte(dataBytes, line, count ,1); //read 1 byte at a time
  191. count+=1;
  192. s = new String(line, 0, 1);
  193. fileData = fileData + s;
  194. pos = fileData.indexOf(boundary, startPos); //check for end of file data i.e boundry value
  195. //out.println(count+"<br>");
  196. }while(pos == -1);
  197. EOF = count - boundary.length();
  198. // out.println(fileData);
  199. //file data extracted
  200.  
  201. /* out.println("<br><br>0. Local File Name = " + strLocalFileName);
  202. out.println("<br><br>1. filename = " + filename);
  203. out.println("<br>2. contentType = " + contentType);
  204. out.println("<br>3. startPos = " + BOF);
  205. out.println("<br>4. endPos = " + EOF);
  206. out.println("<br>5. boundary = " + boundary);
  207. */
  208.  
  209.  
  210.  
  211. //create destination path & save file there
  212. String appPath = application.getRealPath("/");
  213. // out.println("<br>appPath : " + appPath);
  214. String destFolder = appPath + "marksfile/"+session.getAttribute("coleCode").toString().trim().concat("/"); //change this as required
  215. //String destFolder = "/images/photo/"; //change this as required
  216. String mlname=fixfname.substring(fixfname.length()-4,fixfname.length());
  217. java.util.Date date= new java.util.Date();
  218. filename= destFolder + "f"+date.getTime() +mlname;
  219.  
  220.  
  221. //String date1_2=String.valueOf(date);
  222. //int date1=Integer.parseInt(date1_2.substring(date1_2.length()-4,date1_2.length()));
  223. // String filename1="";
  224. // filename1=destFolder+mdeptcode.concat("_").concat(String.valueOf(date1)).concat(".jpg");
  225. // out.println(filename);
  226. try{
  227. //FileWriter fstream = new FileWriter("/home/iemcrp/public_html/iemEn/xx.jpg");
  228. //fstream.close();
  229. out.println(dataBytes);
  230.  
  231. FileOutputStream fileOut = new FileOutputStream(filename);
  232. // byteRead = in1.read(dataBytes, totalBytesRead, formDataLength);
  233.  
  234. //fileOut.write(dataBytes, BOF, (EOF - BOF));
  235.  
  236. //fileOut.write(dataBytes, BOF, EOF );
  237. //fileOut.write(dataBytes, BOF, boundary.length());
  238.  
  239. fileOut.write(dataBytes, BOF, (EOF - BOF));
  240.  
  241.  
  242. fileOut.flush();
  243. fileOut.close();
  244. }catch(Exception ext){
  245. out.println("Error - to Upload");
  246. }
  247. //out.println("<br>File saved as >> " + filename);
  248. /* FileOutputStream fileOut1 = new FileOutputStream(filename1);
  249. fileOut1.write(dataBytes, BOF, (EOF - BOF));
  250. fileOut1.flush();
  251. fileOut1.close();
  252. */
  253.  
  254.  
  255.  
  256. %>
  257. <p align="center">
  258.  
  259.  
  260. </p>
  261. <%
  262. try{
  263. //String filePathOnServer= application.getRealPath("main.csv"); //here main.csv in root folder. FileInputStream fis = new FileInputStream(filePathOnServer); DataInputStream dis = new DataInputStream(fis); //Following code may required some tweaking because I have used readLine() in different manner.while(dis.readLine()){ //Split the line and assign to array than validate and save to db //Here you can use class object for each line} String filePathOnServer= application.getRealPath("main.csv"); //here main.csv in root folder.
  264.  
  265. String fName = filename;
  266. String muser=session.getAttribute("ses_uname").toString();
  267. String thisLine;
  268. // int count=0;
  269. FileInputStream fis = new FileInputStream(fName);
  270. DataInputStream myInput = new DataInputStream(fis);
  271. int i=0;
  272. %>
  273. <%@ page import="java.sql.*" %>
  274. <%@ page import="java.text.Format"%>
  275. <%@page import ="java.util.Date,java.text.SimpleDateFormat"%>
  276.  
  277. <%
  278. try{
  279. //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
  280. //String dbUrl_sub="jdbc:odbc:".concat(mdsnName);
  281. //Connection connl_sub = DriverManager.getConnection(dbUrl_sub,mdataUID,mdataPass) ;
  282. boolean chkOS;
  283. String mos=(System.getProperty("os.name"));
  284. chkOS = mos.startsWith("Windows");
  285. Connection connl_sub;
  286. String dbUrl_sub="jdbc:odbc:sis";
  287. if (chkOS==true){
  288. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
  289. dbUrl_sub="jdbc:odbc:".concat(mdsnName);
  290. connl_sub = DriverManager.getConnection(dbUrl_sub,mdataUID,mdataPass) ;
  291.  
  292. } else{
  293. dbUrl_sub="jdbc:mysql://localhost/iemcrp_iemen?user=iemcrp_sourav&password=piku3976";
  294. Class.forName("org.gjt.mm.mysql.Driver").newInstance(); ;
  295. // Class.forName("com.mysql.jdbc.Driver").newInstance();
  296. dbUrl_sub="jdbc:mysql://localhost/".concat(mdsnName);
  297. connl_sub = DriverManager.getConnection(mdsnName) ;
  298. }
  299. Statement stml;
  300. //out.println(" select subjectcode,subname,prio from asrp_unittestsubjectmaster11 where (class=11 or class='XI') and (streamcode='"+mstream+"' or streamcode='All') and (sub_subjectcode=subjectcode) order by prio");
  301. String mpara=session.getAttribute("ses_csv").toString();
  302. out.println(mpara);
  303. //String mparacsv=batch+","+mmdegree+","+stream+","+meyear+","+memonth+","+msem+","+msubsel;
  304.  
  305.  
  306. String mpara_Arr[]=mpara.split(",");
  307. String mbatch=mpara_Arr[0];
  308. String mdegree=mpara_Arr[1];
  309. String mstream=mpara_Arr[2];
  310. String myear=mpara_Arr[3];
  311. String memonth=mpara_Arr[4];
  312. String msem=mpara_Arr[5];
  313. String msubsel=mpara_Arr[6];
  314. String msec=mpara_Arr[7];
  315.  
  316. String menrlno="";
  317. String mmarks="";
  318. String str1="";
  319. //Following code may required some tweaking because I have used readLine() in different manner.
  320. while ((thisLine = myInput.readLine()) != null)
  321. {
  322. String strar[] = thisLine.split(",");
  323. menrlno="";
  324. mmarks="";
  325.  
  326. try{
  327. if (strar[0].trim().length()>0){
  328. menrlno=strar[0].trim();
  329. }
  330. }catch(Exception e){
  331. break;
  332. }
  333. try{
  334. if (strar[1].trim().length()>0){
  335. mmarks=strar[1].trim();
  336. }
  337. }catch(Exception e){
  338. break;
  339. }
  340.  
  341. str1="update aerp_unit_marks_resuslt set marks="+mmarks+" where enrlno='"+menrlno+"' and subject_code='"+msubsel+"' and examyear="+myear+" and exammonth="+memonth;
  342.  
  343. stml=connl_sub.createStatement();
  344. int j1=stml.executeUpdate(str1);
  345. stml.close();
  346. }
  347. connl_sub.close();
  348.  
  349. %>
  350. <form name="form1" id="form1" action="unitmarksEntrySubmitDone.jsp" method="post">
  351. <input type="hidden" name="tbatch" value="<%=mbatch%>">
  352. <input type="hidden" name="tdegree" value="<%=mdegree%>">
  353. <input type="hidden" name="tstream" value="<%=mstream%>">
  354. <input type="hidden" name="texamyear" value="<%=myear%>">
  355. <input type="hidden" name="texammonth" value="<%=memonth%>">
  356. <input type="hidden" name="tsem" value="<%=msem%>">
  357. <input type="hidden" name="subsel" value="<%=msubsel%>">
  358. <input type="hidden" name="tsec" value="<%=msec%>">
  359.  
  360.  
  361. <input type="submit">
  362.  
  363. </form>
  364. <script>
  365. alert("Update Successfully");
  366. form1.submit();
  367. </script>
  368.  
  369. <%
  370. }catch(Exception ex){
  371. out.println(ex.toString());
  372.  
  373. }
  374. } catch ( Exception ex ) {
  375. out.println(ex.toString());
  376. }
  377.  
  378.  
  379.  
  380.  
  381.  
  382. }else{
  383. out.println("Upload Again");
  384. }
  385. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement