Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. <%@ page
  2. import="java.util.*, bloggen.domain.*, bloggen.io.*, dk.au.hum.imv.persistence.db.JDBCConnectionFactory, bloggen.io.UserDAO, bloggen.domain.User"%>
  3. <%@ include file="Header.jsp"%>
  4.  
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta charset="UTF-8" />
  9. <%@ page language="java" contentType="text/html; charset=UTF-8"
  10. pageEncoding="UTF-8"%>
  11. <title>Music</title>
  12. <link rel="stylesheet" href="stylesheet.css" />
  13. </head>
  14. <body>
  15. <%
  16. String commentBody = request.getParameter("commentBody");
  17. String submitKnap = request.getParameter("submit-knap");
  18.  
  19. if(request.getParameter("submit-knap") != null) {
  20. long currentUser = model.getUserId();
  21. JDBCConnectionFactory.initManualConnectionHandling("jdbc:mysql://student.hum.au.dk:3306/u201507985",
  22. "u201507985", "Butm51uR", "com.mysql.jdbc.Driver");
  23. String postId = request.getParameter("submit-knap");
  24. int convertIdToInt = Integer.parseInt(postId);
  25. CommentDAO.saveComment(model.getUserName(), commentBody, convertIdToInt);
  26. String redirectUrl = "/Aflevering_13/Index.jsp";
  27. response.sendRedirect(redirectUrl);
  28. }
  29.  
  30.  
  31. %>
  32. <div class = "containerWEB">
  33.  
  34. <form action="Index.jsp" method="post">
  35. <div id="form" action="Index.jsp" method="post">
  36. <div class="form-horizontal">
  37.  
  38. <fieldset>
  39. <legend>Nyt blogindlæg</legend>
  40. <div class="form-group">
  41. <table>
  42. <tr>
  43. <label class="col-md-4 control-label">Genre</label>
  44. <td><select name="genre">
  45. <option value="Jazz">Jazz</option>
  46. <option value="Rock">Rock</option>
  47. <option value="Hiphop">Hiphop</option>
  48. <option value="Pop">Pop</option>
  49. <option value="Electronic">Electronic</option>
  50. </select></td>
  51. </tr>
  52. </table>
  53. </div>
  54.  
  55.  
  56. <div class="form-group">
  57. <label class="col-md-4 control-label" for="postTitle"> Title</label>
  58. <div class="col-md-4">
  59. <input type="text" name="postTitle" id="blogTitle"
  60. class="form-control input-md" />
  61. </div>
  62. </div>
  63.  
  64. <div class="form-group">
  65. <label class="col-md-4 control-label"> Text</label>
  66. <div class="col-md-4">
  67. <textarea id="text" class="form-control" name="postText" rows="4"
  68. cols="50"></textarea>
  69. </div>
  70. </div>
  71.  
  72.  
  73. <div class="form-group">
  74. <label class="col-md-4 control-label" for="submit">Submit</label>
  75. <div class="col-md-4">
  76. <input id="submit" type="submit" value="submit" name="submit"
  77. class="btn btn-success">
  78. </div>
  79. </div>
  80.  
  81. </fieldset>
  82. </div>
  83. </div>
  84. </form>
  85. </div>
  86.  
  87. <%
  88. String genre = request.getParameter("genre");
  89. String title = request.getParameter("postTitle");
  90. String text = request.getParameter("postText");
  91. long id = model.getUserId();
  92.  
  93. User user = UserDAO.getUserById(id);
  94.  
  95. if (request.getParameter("submit") != null) {
  96. PostDao.Post(title, user.getUserName(), text, genre);
  97. }
  98. %>
  99.  
  100. <%
  101. ArrayList<Post> newPosts = PostDao.getAllPosts();
  102. %>
  103. <%
  104. for (Post posts : newPosts) {
  105. %>
  106.  
  107.  
  108.  
  109. <div class="page">
  110.  
  111. <h3><%=posts.getTitle()%></h3>
  112. <div class="details">
  113. <ul>
  114. <li><%=posts.getAuthor()%></li>
  115. <li><%=posts.getDate()%></li>
  116. <li><%=posts.getGenre()%></li>
  117. </ul>
  118. <div class="content">
  119. <p><%=posts.getText()%></p>
  120. </div>
  121. <div class = "commentBox">
  122. <fieldset>
  123. <form
  124. action="Index.jsp" method="post">
  125. <textarea id="commentBody" name ="commentBody" placeholder = "Text"> </textarea>
  126. <button name ="submit-knap"> Send </button>
  127. </form>
  128. </fieldset>
  129. </div>
  130. <hr>
  131. </div>
  132. </div>
  133.  
  134.  
  135. <%
  136. ArrayList<Comment> newComments = CommentDAO.getCommentsForPostId(posts.getPost_id());
  137.  
  138. for (Comment comments : newComments) {
  139. %>
  140.  
  141.  
  142.  
  143.  
  144. <h5>Comment Title <%=comments.getUsername() %> </h5>
  145. <p> Text <%=comments.getText() %>
  146. <p> <%=comments.getDate() %>
  147.  
  148.  
  149.  
  150.  
  151. <%
  152. }
  153. %>
  154.  
  155.  
  156. <%
  157. }
  158. %>
  159. <script type="text/javascript">
  160. function resettoggle() {
  161. var e = document.getElementById('form');
  162. e.style.display = 'none';
  163. }
  164.  
  165. function toggle_visibility(id) {
  166. var e = document.getElementById(id);
  167. if (e.style.display == 'none')
  168. e.style.display = 'block';
  169. else
  170. e.style.display = 'none';
  171. }
  172. </script>
  173. <%@ include file="Footer.jsp"%>
  174.  
  175.  
  176. </body>
  177. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement