Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
1,080
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.78 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <%@ page isThreadSafe="false" %>
  4. <%@ page import="java.sql.*" %>
  5. <%@ page import="java.io.*,java.util.*,javax.mail.*"%>
  6. <%@ page import="javax.mail.internet.*,javax.activation.*"%>
  7. <%@ page import="javax.servlet.http.*,javax.servlet.*"%>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>Add Faculty</title>
  11. <link rel="stylesheet" type="text/css" href="css/style.css" />
  12. <link rel="shortcut icon" href="favicon.png" />
  13. <script type="text/javascript" src="js/modernizr-1.5.min.js"></script>
  14. </head>
  15. <body>
  16. <div>
  17. <div class="dropdown" style="float:right;">
  18. <button class="user dropbtn"></button>
  19. <div class="dropdown-content">
  20. <a href="AdminHome.jsp">Home</a>
  21. <a href="UserProfile.jsp">Profile</a>
  22. <a href="ChangePassword.jsp">Change Password</a>
  23. <a href="LoginPage.html">Logout</a>
  24. </div>
  25. </div>
  26. <!-- javascript at the bottom for fast page loading -->
  27. <script type="text/javascript" src="js/jquery.min.js"></script>
  28. <script type="text/javascript" src="js/jquery.easing.min.js"></script>
  29. <script type="text/javascript" src="js/jquery.lavalamp.min.js"></script>
  30. <script type="text/javascript" src="js/image_fade.js"></script>
  31. <script type="text/javascript">
  32. $(function () {
  33. $("#lava_menu").lavaLamp({
  34. fx: "backout",
  35. speed: 700
  36. });
  37. });
  38. </script>
  39. </div>
  40. </body>
  41. <%
  42. String fname = request.getParameter("fname");
  43. String lname = request.getParameter("lname");
  44. String email = request.getParameter("email");
  45. String username = request.getParameter("username");
  46. String password = request.getParameter("pswd");
  47. String dept = request.getParameter("dept");
  48. String sub = request.getParameter("sub");
  49. String loc = request.getParameter("loc");
  50. int subid = 0;
  51. int fid = 0;
  52. try {
  53. //inserting data into database
  54. Statement statement1 = null;
  55. ResultSet rs1 = null;
  56. String connectionURL1 = "jdbc:mysql://localhost:3306/schedulingdatabase";
  57. Connection connection1 = null;
  58. Class.forName("com.mysql.jdbc.Driver").newInstance();
  59. connection1 = DriverManager.getConnection(connectionURL1, "teamd", "Teamd@1234");
  60. Statement st1 = connection1.createStatement();
  61. //facultyID-noOfdays-day-section-room-course-time//
  62. // insert into accountant values('"+username+"','"+"faculty"+"','"+password++ "')
  63. //int i = st1.executeUpdate("insert into accountant values('+username+')");
  64. //inserting username and pwd into accountant values
  65. int i = st1.executeUpdate("insert into accountant values('" + username + "','" + "faculty" + "','" + password + "')");
  66.  
  67. } catch (Exception e) {
  68. }
  69. try {
  70. // inserting data into database
  71. Statement statement = null;
  72. ResultSet rs = null;
  73. String connectionURL = "jdbc:mysql://localhost:3306/schedulingdatabase";
  74. Connection connection = null;
  75. Class.forName("com.mysql.jdbc.Driver").newInstance();
  76. connection = DriverManager.getConnection(connectionURL, "teamd", "Teamd@1234");
  77. Statement st = connection.createStatement();
  78. String QueryString = "Select SubjectId from subject where Name='" + sub + "'";
  79. rs = st.executeQuery(QueryString);
  80. if (rs.next()) {
  81. subid = Integer.parseInt(rs.getString(1));
  82. %>
  83. <h3><%=subid%></h3>
  84. <h3><%=fname%></h3>
  85. <h3><%=lname%></h3>
  86. <h3><%=email%></h3>
  87. <h3><%=dept%></h3>
  88. <h3><%=sub%></h3>
  89. <%
  90. }
  91. } catch (Exception e) {
  92. }
  93. try {
  94. //inserting data into database
  95. Statement statement = null;
  96. ResultSet rs = null;
  97. String connectionURL = "jdbc:mysql://localhost:3306/schedulingdatabase";
  98. Connection connection = null;
  99. Class.forName("com.mysql.jdbc.Driver").newInstance();
  100. connection = DriverManager.getConnection(connectionURL, "teamd", "Teamd@1234");
  101. Statement st = connection.createStatement();
  102. String QueryString = "Select MAX(FacultyId) from faculty";
  103. rs = st.executeQuery(QueryString);
  104. if (rs.next()) {
  105. fid = Integer.parseInt(rs.getString(1));
  106. fid += 1;
  107. }
  108. } catch (Exception e) {
  109. }
  110. String jtype = request.getParameter("jtype");
  111. int chrs = Integer.parseInt(request.getParameter("chrs"));
  112. try {
  113. Statement statement = null;
  114. ResultSet rs = null;
  115. String connectionURL = "jdbc:mysql://localhost:3306/schedulingdatabase";
  116. Connection connection = null;
  117. Class.forName("com.mysql.jdbc.Driver").newInstance();
  118. connection = DriverManager.getConnection(connectionURL, "teamd", "Teamd@1234");
  119. Statement st = connection.createStatement();
  120. //inserting data into faculty table
  121. String qury = "insert into faculty values('" + fname + " " + lname + "','" + fid + "','" + subid + "','" + dept + "','" + loc + "','" + sub + "','" + chrs + "',null,null,'" + jtype + "','" + email + "',null,'" + username + "')";
  122. int i = st.executeUpdate(qury);
  123. System.out.println("i : " + i);
  124. // sending mail to newly added faculty by using smtp protocol
  125. if (i > 0) {
  126. System.out.println("inside if!");
  127. Properties props = new Properties();
  128. props.put("mail.smtp.host", "smtp.gmail.com");
  129. props.put("mail.smtp.socketFactory.port", "587");
  130. props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  131. props.put("mail.smtp.auth", "true");
  132. props.put("mail.smtp.port", "587");
  133. props.put("mail.smtp.starttls.enable", "true");
  134. String course = sub;
  135. Session sess = Session.getInstance(props, new javax.mail.Authenticator() {
  136. protected PasswordAuthentication getPasswordAuthentication() {
  137. return new PasswordAuthentication("sanketselokar1234@gmail.com", "Sandy@1992");//change accordingly
  138. }
  139. });
  140. String to = email;
  141. try {
  142. MimeMessage message = new MimeMessage(sess);
  143. message.setFrom(new InternetAddress("sanketselokar1234@gmail.com"));//change accordingly
  144. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
  145. message.setSubject("A new Faculty was Added");
  146. message.setText("Hello,\n A new faculty member was added:\n\n Name : " + fname + "\n\n Departmenet : " + dept + "\n\n Username: " + username + "\n\n password " + password + "+\n\n Subject : " + sub + ".\n Thank You\n");
  147. Transport.send(message);
  148. } catch (MessagingException e) {
  149. e.printStackTrace();
  150. throw new RuntimeException(e);
  151. }
  152. out.println("<script type=\"text/javascript\">");
  153. out.println("alert('Faculty added successfully!! ');");
  154. out.println("location='AdminHome.jsp';");
  155. out.println("</script>");
  156. } else {
  157. out.println("<script type=\"text/javascript\">");
  158. out.println("alert('Could not add faculty!! ');");
  159. out.println("location='AddFaculty.jsp';");
  160. out.println("</script>");
  161. }
  162. } catch (Exception e) {
  163. System.out.println("Could not Update faculty details!!");
  164. e.printStackTrace();
  165. }
  166. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement