Guest User

forum.jsp

a guest
May 25th, 2016
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.39 KB | None | 0 0
  1. <%@page import="dk.au.hum.imv.persistence.db.JDBCConnectionFactory,
  2. java.util.*, DAO.*, java.sql.*, java.lang.String, java.lang.*, java.util.Date, domain.*"%>
  3. <jsp:include page="header.jsp" />
  4. <%
  5.  
  6. SessionModel model = (SessionModel)request.getSession().getAttribute("sessionModel");
  7. if (!model.isLoggedIn()) {
  8.     response.sendRedirect("login.jsp"); //send bruger til login
  9.     return; //afslut afvikling af resten af siden
  10. }
  11.  
  12. Student student = StudentDAO.getStudentById(model.getUserId());
  13.  
  14. String studentName = student.getName();
  15. PostDAO postDao = new PostDAO();
  16.  
  17. %>
  18. <title>Studerende</title>
  19. <%
  20.  
  21.     String title = request.getParameter("title");
  22.     String body = request.getParameter("body");
  23.     String cat = request.getParameter("cat");
  24.    
  25.  
  26.     String createButton = request.getParameter("submit");
  27.     if (createButton != null) {
  28.         long currentUser = model.getUserId();
  29.         JDBCConnectionFactory.initManualConnectionHandling("jdbc:mysql://student.hum.au.dk:3306/infprojekt",
  30.         "infprojekt", "1daKEoig", "com.mysql.jdbc.Driver");
  31.         Post mitpost = new Post(title, body, cat, currentUser);
  32.         PostDAO.setPost(mitpost);
  33.         String redirectURL = "/Studentsprojekt/forum.jsp";
  34.         response.sendRedirect(redirectURL);
  35.         }
  36.    
  37.     String commentTitle = request.getParameter("commentTitle");
  38.     String commentBody = request.getParameter("commentBody");
  39.    
  40.     if(request.getParameter("submit-knap") != null) {
  41.         long currentUser = model.getUserId();
  42.         String postId = request.getParameter("submit-knap");
  43.         int convertIdToInt = Integer.parseInt(postId);
  44.         JDBCConnectionFactory.initManualConnectionHandling("jdbc:mysql://student.hum.au.dk:3306/infprojekt",
  45.         "infprojekt", "1daKEoig", "com.mysql.jdbc.Driver");
  46.         Comment mincomment = new Comment(commentTitle, commentBody, convertIdToInt, currentUser);
  47.         CommentDAO.setComment(mincomment);
  48.         String redirectURL = "/Studentsprojekt/forum.jsp";
  49.         response.sendRedirect(redirectURL);
  50.         }
  51. %>
  52. <%
  53. JDBCConnectionFactory.initManualConnectionHandling("jdbc:mysql://student.hum.au.dk:3306/infprojekt",
  54. "infprojekt", "1daKEoig", "com.mysql.jdbc.Driver");
  55. ArrayList<Post> postBeer = PostDAO.getPostByCat("Øl");
  56. ArrayList<Post> postReading = PostDAO.getPostByCat("Læsning");  
  57. %>
  58. <div class="container">
  59.     <div class="blog-header">
  60.         <h1 class="blog-title">Forum</h1>
  61.         <p class="lead blog-description">Herunder kommer to forummer hhv. læsning og øl</p>
  62.         <hr>
  63.     </div>
  64.     <div class="row">
  65.  
  66.         <div class="col-sm-8 blog-main">
  67.        
  68.             <div class="blog-header">
  69.                 <h2 class="blog-title"><strong>Øl</strong></h2>
  70.                 <p class="lead blog-description">Herunder kommer posts i kategorien Øl</p>
  71.                 <hr>
  72.             </div>
  73.    
  74.         <div class="blog-post">
  75.                 <%
  76.                 for (Post posts : postBeer) {                  
  77.                 %>
  78.             <h3 class="blog-post-title">Post titel: <%=posts.getPostTitle() %></h3>
  79.             <p class="blog-post-meta" id="cat">Kategori: <%=posts.getPostCat() %></p>
  80.             <p class="blog-post-meta" id="date">Dato: <strong><%=posts.convertDate() %></strong></p>
  81.             <p>Oprettet af: <%= postDao.getPostAuthor(posts.getStudentId()) %></p>
  82.             <p id="beskrivelse">Beskrivelse: <%=posts.getPostBody() %></p>
  83.             <FORM action="forum.jsp" NAME="form1" METHOD="POST">
  84.             <!-- Text input-->
  85.             <div class="form-group">
  86.                 <div class="col-md-4" style="width:100%;">
  87.                     <input id="commentTitle" name="commentTitle" type="text" placeholder="Post titlen" class="form-control input-md">
  88.    
  89.                  </div>
  90.             </div>
  91.  
  92.             <!-- Description input -->
  93.             <div class="form-group">
  94.               <div class="col-md-4" style="width:100%;">                    
  95.                 <textarea class="form-control" id="commentBody" name="commentBody" placeholder="Skriv dit post indhold her:"></textarea>
  96.               </div>
  97.             </div>
  98.             <button name="submit-knap" class="btn btn-default" value="<%=posts.getPostId() %>" class="form-control input-md" id="<%=posts.getPostId() %>">Send</button>
  99.             </FORM>
  100.             <hr>
  101.                 <%
  102.                 }
  103.                 %>
  104.         </div>
  105.         <!-- /.blog-post -->
  106.        
  107.             <div class="blog-header">
  108.                 <h2 class="blog-title"><strong>Læsning</strong></h2>
  109.                 <p class="lead blog-description">Herunder kommer posts i kategorien læsning</p>
  110.                 <hr>
  111.             </div>
  112.    
  113.         <div class="blog-post">
  114.                 <%
  115.                 for (Post posts : postReading) {                   
  116.                 %>
  117.             <h3 class="blog-post-title">Post titel: <%=posts.getPostTitle() %></h3>
  118.             <p class="blog-post-meta" id="cat">Kategori: <%=posts.getPostCat() %></p>
  119.             <p class="blog-post-meta" id="date">Dato: <strong><%=posts.convertDate() %></strong></p>
  120.             <p>Oprettet af: <%= postDao.getPostAuthor(posts.getStudentId()) %></p>
  121.             <p id="beskrivelse">Beskrivelse: <%=posts.getPostBody() %></p>
  122.             <hr>
  123.                 <%
  124.                 }
  125.                 %>
  126.         </div>
  127.         <!-- /.blog-post -->
  128.        
  129.         </div>
  130.          <div class="col-sm-3 col-sm-offset-1 blog-sidebar">
  131.           <div class="sidebar-module sidebar-module-inset">
  132.             <h4>Opret en post:</h4>
  133.  
  134. <form action="forum.jsp" method="post" class="form-horizontal">
  135. <fieldset>
  136.  
  137.  
  138. <div class="form-group">
  139.   <div class="col-md-4" style="width:100%;">
  140.   <input id="title" name="title" type="text" placeholder="Post titlen" class="form-control input-md">
  141.    
  142.   </div>
  143. </div>
  144.  
  145. <div class="form-group">
  146.   <div class="col-md-4" style="width:100%;">                    
  147.     <textarea class="form-control" id="body" name="body" placeholder="Skriv dit post indhold her:"></textarea>
  148.   </div>
  149. </div>
  150. <div class="form-group ">
  151.   <div class="col-md-4" style="width:100%;">                    
  152.       <select class="select form-control" id="cat" name="cat">
  153.         <option value="Øl">
  154.             Øl
  155.         </option>
  156.         <option value="Læsning">
  157.             Læsning
  158.         </option>
  159.       </select>
  160.   </div>
  161. </div>
  162.  
  163. <div class="form-group">
  164.   <div class="col-md-4">
  165.     <button id="submit" name="submit" class="btn btn-default" class="form-control input-md">Send</button>
  166.   </div>
  167. </div>
  168.  
  169. </fieldset>
  170. </form>
  171.           </div>
  172.           <div class="sidebar-module">
  173.             <h4>Archives</h4>
  174.            
  175.             <ol class="list-unstyled">
  176.               <li><a href="#">March 2014</a></li>
  177.               <li><a href="#">February 2014</a></li>
  178.               <li><a href="#">January 2014</a></li>
  179.               <li><a href="#">December 2013</a></li>
  180.               <li><a href="#">November 2013</a></li>
  181.               <li><a href="#">October 2013</a></li>
  182.               <li><a href="#">September 2013</a></li>
  183.               <li><a href="#">August 2013</a></li>
  184.               <li><a href="#">July 2013</a></li>
  185.               <li><a href="#">June 2013</a></li>
  186.               <li><a href="#">May 2013</a></li>
  187.               <li><a href="#">April 2013</a></li>
  188.             </ol>
  189.           </div>
  190.           <div class="sidebar-module">
  191.             <h4>Elsewhere</h4>
  192.             <ol class="list-unstyled">
  193.               <li><a href="#">GitHub</a></li>
  194.               <li><a href="#">Twitter</a></li>
  195.               <li><a href="#">Facebook</a></li>
  196.             </ol>
  197.           </div>
  198.         </div><!-- /.blog-sidebar -->
  199.         </div>
  200.        
  201. </div>
  202. <script>
  203. /*
  204. $(document).ready(function () {
  205.     $(".submit").click(function() {
  206.         alert($(this).attr("id"))
  207.     })
  208. })
  209. */
  210. </script>
  211. <jsp:include page="footer.jsp" />
  212. </body>
  213. </html>
Add Comment
Please, Sign In to add comment