Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. package posidex.Demo.UAM;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.sql.Connection;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.util.ArrayList;
  10. import java.util.Properties;
  11.  
  12. import org.apache.logging.log4j.LogManager;
  13. import org.apache.logging.log4j.Logger;
  14. import org.apache.struts2.dispatcher.SessionMap;
  15.  
  16. import posidex.Demo.DAO.DataModel;
  17. import posidex.Demo.DAO.GetDBCOnnection;
  18. import posidex.Demo.DAO.SessionBase;
  19.  
  20. public class LoginAction extends SessionBase {
  21.  
  22. Connection conn = null;
  23.  
  24. Properties readFile = new Properties();
  25.  
  26. FileInputStream fileStream = null;
  27.  
  28. ResultSet recordSet = null;
  29.  
  30. DataModel resultModel = null;
  31.  
  32. PreparedStatement forResult = null;
  33.  
  34. SessionMap<String, Object> loginMap = null;
  35.  
  36. ArrayList<DataModel> list = new ArrayList<DataModel>();
  37.  
  38. public ArrayList<DataModel> getList() {
  39. return list;
  40. }
  41.  
  42. public void setList(ArrayList<DataModel> list) {
  43. this.list = list;
  44. }
  45.  
  46. Logger log = LogManager.getLogger(LoginAction.class);
  47.  
  48. public String getDbDetails() {
  49.  
  50. try {
  51.  
  52. log.debug("Inside getDbDetails Method");
  53. fileStream = new FileInputStream(
  54. "/home/ast-developer/NewWorkspace/User Access Management/src/Database.properties");
  55.  
  56. readFile.load(fileStream);
  57.  
  58. conn = GetDBCOnnection.getDbConnection();
  59.  
  60. if (conn != null) {
  61. forResult = conn.prepareStatement(readFile.getProperty("db.selectQuery"));
  62.  
  63. recordSet = forResult.executeQuery();
  64.  
  65. }
  66.  
  67. if (recordSet != null) {
  68.  
  69. while (recordSet.next()) {
  70.  
  71. resultModel = new DataModel();
  72. resultModel.setUserId(recordSet.getInt(1));
  73. resultModel.setFirstName(recordSet.getString(2));
  74. resultModel.setLastName(recordSet.getString(3));
  75. resultModel.setEmailId(recordSet.getString(4));
  76. resultModel.setUserRole(recordSet.getString(5));
  77. resultModel.setUserPhone(recordSet.getLong(6));
  78. resultModel.setUserStatus(recordSet.getString(7));
  79. list.add(resultModel);
  80. }
  81.  
  82. loginMap = getSession();
  83.  
  84. loginMap.put("mylist", list);
  85.  
  86. setSession(loginMap);
  87.  
  88. }
  89. } catch (IOException | SQLException e) {
  90. // TODO Auto-generated catch block
  91. e.printStackTrace();
  92.  
  93. } finally {
  94. try {
  95. fileStream.close();
  96. conn.close();
  97. forResult.close();
  98. recordSet.close();
  99. } catch (SQLException | IOException e) {
  100. // TODO Auto-generated catch block
  101. e.printStackTrace();
  102. }
  103.  
  104. }
  105.  
  106. return "success";
  107. }
  108.  
  109. }
  110.  
  111. <%@ page language="java" contentType="text/html; charset=UTF-8"
  112. pageEncoding="UTF-8"%>
  113.  
  114. <%@ taglib prefix="s" uri="/struts-tags"%>
  115. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  116. <html>
  117. <head>
  118. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  119. <title>View User Page</title>
  120. </head>
  121. <body>
  122. <s:form action="createUser" method="post" id="options">
  123. <div id="outer div"
  124. style="width: 180px; display: inline-block; margin: 2px">
  125. <select
  126. style="width: 150px; vertical-align: top; height: 30px; margin: 1px"
  127. name="user_Status" id="status_List">
  128. <option selected>Active</option>
  129. <option>Suspended</option>
  130. </select>
  131. </div>
  132. <div style="display: inline-block; margin: 1px">
  133. <div>
  134. <s:submit
  135. style="width: 150px; align: left; height: 30px; margin:1px"
  136. value="Create User"></s:submit>
  137. </div>
  138. </div>
  139. </s:form>
  140.  
  141. <s:form action="editUser" method="post">
  142.  
  143. <div id="results" style="border: solid 1px #444; margin: 3px">
  144.  
  145. <table>
  146.  
  147. <tr>
  148. <td>User ID</td>
  149. <td>First Name</td>
  150. <td>Last Name</td>
  151. <td>Email Id</td>
  152. <td>Role</td>
  153. <td>Contact</td>
  154. <td>Status</td>
  155. <td>Action</td>
  156.  
  157. </tr>
  158. <s:iterator value="list">
  159. <tr>
  160. <td><s:property value="userId"></s:property></td>
  161. <td><s:property value="firstName"></s:property></td>
  162. <td><s:property value="lastName"></s:property></td>
  163. <td><s:property value="emailId"></s:property></td>
  164. <td><s:property value="userRole"></s:property></td>
  165. <td><s:property value="userPhone"></s:property></td>
  166. <td><s:property value="userStatus"></s:property></td>
  167. <td><s:url value="EditUserAction.action" var="url">
  168. <s:param name="userId" value="userID" />
  169. </s:url> <s:a href="%{url}">
  170. <s:submit value="E" />
  171. </s:a></td>
  172.  
  173. </tr>
  174. </s:iterator>
  175. </table>
  176. </div>
  177.  
  178. </s:form>
  179. </body>
  180. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement