JSP

 

 

DTO

QnaVO

package net.macaronics.web.dto;

import java.sql.Timestamp;

public class QnaVO {
	
	private int qseq; //글번호
	private String subject;  //제목
	private String content;  //문의 내용
	private String reply; //답변 내용
	private String id; //작성자 아이디
	private String rep; //답변 유무
	private Timestamp indate; //작성일

 

 

DAO

AdminQnaDAO

package net.macaronics.web.admin.controller.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import config.MybatisService;
import net.macaronics.web.dto.QnaVO;

public class AdminQnaDAO {

	private static final Logger logger =LogManager.getLogger(AdminQnaDAO.class);
	
	private SqlSession sqlSession;
	
	private static AdminQnaDAO instance; 
	
	private AdminQnaDAO(){
		
	}
	
	public static AdminQnaDAO getInstance(){
		if(instance==null){
			instance=new AdminQnaDAO();
		}
		return instance;
	}
	
	
	// 관리자 qna 목록 출력 
	public List<QnaVO> listAllQna(){
		List<QnaVO> list=new ArrayList<>();
		try{
			sqlSession=MybatisService.getFactory().openSession();
			list=sqlSession.selectList("qna.listAllQna");		
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			MybatisService.sessionClose(sqlSession);
		}
		return list;
	}
	
	
	//qna update 
	public void updateQna(QnaVO qnaVO){
		try{
			sqlSession=MybatisService.getFactory().openSession();
			sqlSession.update("qna.updateQna", qnaVO);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			sqlSession.commit();
			MybatisService.sessionClose(sqlSession);
		}
	}
	
	
	
	
	
	
}

 

 

mapper

	<update id="updateOrderResult">
		update TBL_ORDER_DETAIL set result='2' where odseq=#{odseq}
	</update>

 

 

 

목록 보기

AdminQnaListAction

package net.macaronics.web.admin.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.macaronics.web.admin.controller.dao.AdminQnaDAO;
import net.macaronics.web.controll.action.Action;
import net.macaronics.web.dao.QnaDAO;
import net.macaronics.web.dto.QnaVO;

public class AdminQnaListAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String url="admin/qna/qnaList.jsp";
		
		AdminQnaDAO qnaDAO =AdminQnaDAO.getInstance();
		List<QnaVO> qnaList =qnaDAO.listAllQna();
		
		request.setAttribute("qnaList", qnaList);

		request.getRequestDispatcher(url).forward(request, response);
	}

}










 

qnaList.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>    
<!DOCTYPE html>
<html class="no-js">   
    <head>
<jsp:include page="../../include/AdminHeader.jsp" />
    </head>   
    <body>
 <jsp:include page="../../include/AdminTopFixMenu.jsp" />   
   
        
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span3" id="sidebar">
					 <jsp:include page="../../include/AdminLeftMenu.jsp" />   
                </div>
                
                <!--/span-->
                <div class="span9" id="content">
                    <div class="row-fluid">
                        <div class="alert alert-success">
							<button type="button" class="close" data-dismiss="alert">&times;</button>
                            <h4>답변 리스트</h4>
                        </div>
                        
                        	
                    	</div>
                   
                   
                   <div>
                   	 
                   	 <form method="post" action="" name="frm">
                   	 <div class="table-responsive">
                   	 <table class="table">
                   	   <tr class="success">
                   	   	 <th>번호(답변여부)</th>
                   	   	 <th>제목</th>
                   	   	 <th>작성자</th>
                   	   	 <th>작성일</th>
                   	   </tr>
                   	  <c:if test="${empty qnaList or qnaList.size()==0 }" >
                   	  	<tr>
                   	  	  <td colspan="6" class="text-center"> 작성된 글이 없습니다.</td>
                   	  	</tr>
                   	  </c:if> 
                   	  <c:forEach items="${qnaList}" var="qna">
                   	       <tr> 
	                   	   <td>
	                   	   ${qna.qseq }
	                   	    <c:choose>
	                   	    	<c:when test="${qna.rep=='1' }">
	                   	    	 <span style="color:red;">(미처리)</span>
	                   	    	</c:when>
	                   	    	<c:otherwise>
	                   	    	<span>(답변처리완료)</span>
	                   	    	</c:otherwise>
	                   	    </c:choose>
	                   	   </td>
	                   	   <td><a href="MacaronicsServlet?command=admin_qna_detail&qseq=${qna.qseq}" >${qna.subject }</a></td>
	                   	   <td>${qna.id }</td>
	                   	   <td><fmt:formatDate  type="date"  value="${qna.indate }" /></td>
	                   	   </tr>
                   	   </c:forEach>

                   	 </table>
                   	 </div>
                   	 </form>
                   	 
                   </div>
                    
                    </div>
                </div>
         
           
            </div>
            <hr>


 <jsp:include page="../../include/AdminFooter.jsp" />   
 
 
 
         

 

 

 

QnA 답변 상세보기 및 답변하기

 

 

AdminQnaDetailAction

package net.macaronics.web.admin.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.macaronics.web.controll.action.Action;
import net.macaronics.web.dao.QnaDAO;
import net.macaronics.web.dto.QnaVO;

public class AdminQnaDetailAction implements Action{

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String url="admin/qna/qnaDetail.jsp";
		
		String qseq=request.getParameter("qseq").trim();
		
		QnaDAO qnaDAO =QnaDAO.getInstance();
		QnaVO qnaVO =qnaDAO.getQna(Integer.parseInt(qseq));
		String str =qnaVO.getContent();
		String content=str.replaceAll("&lt;", "<").replaceAll("&gt;", ">");
		qnaVO.setContent(content);
		
		
		request.setAttribute("qnaVO", qnaVO);
		
		request.getRequestDispatcher(url).forward(request, response);
	}

	
}

 

 

 

 

qnaDetail.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>    
<!DOCTYPE html>
<html class="no-js">   
    <head>
<jsp:include page="../../include/AdminHeader.jsp" />
        <!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="../../Bootstrap-Admin/vendors/bootstrap-wysihtml5/src/bootstrap-wysihtml5.css"></link>

    </head>   
    <body>
 <jsp:include page="../../include/AdminTopFixMenu.jsp" />   
   
        
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span3" id="sidebar">
					 <jsp:include page="../../include/AdminLeftMenu.jsp" />   
                </div>
                
                <!--/span-->
                <div class="span9" id="content">
                    <div class="row-fluid">
                        <div class="alert alert-success">
							<button type="button" class="close" data-dismiss="alert">&times;</button>
                            <h4>Q & A 게시판</h4>
                        </div>
                        	
                    	</div>
                   
                   
                   <div>
                   	 
                  
                   	 <div class="table-responsive">
                   	 <table class="table">
                   	   	<tr>
                   	   		<th>제목</th>
                   	   		<td>${qnaVO.subject } ${qnaVO.rep }</td>
                   	   	</tr>
						
						<tr>
							<th>등록일</th>
							<td><fmt:formatDate value="${qnaVO.indate }"  type="date" /></td>
						</tr>

						<tr>
							<th>내용</th>
							<td>
								${qnaVO.content }
							</td>
						</tr>
						
						<c:choose>
							<c:when test="${qnaVO.rep=='1' }">
							<form action="/MacaronicsServlet?command=admin_qna_repsave" method="post" >
							 <table class="table">
								<tr>
									<th>답변하기</th>
									<td>
										<textarea id="bootstrap-editor" style="width:98%;height:200px;" name="reply" ></textarea>
									</td>
								</tr>
								<tr>
								 <td></td>
								 <td> 
								 <input type="hidden" value="${qnaVO.qseq}" name="qseq">
								 <input type="submit" value="답변달기" class="btn btn-success"></td>
								</tr>
							</table>
							</form>	
							</c:when>
							<c:otherwise>
							   <table class="table">
							     <tr>
							       <th>답변 내용</th>
							       <td>${qnaVO.reply }</td>
							      </tr>
							   </table>
							</c:otherwise>				
						</c:choose>
			
						<tfoot>
							<tr>
								<td colspan="2" class="text-center" style="text-align: center;">
									<a href="MacaronicsServlet?command=admin_qna_list"  class="btn btn-primary">목록</a>
								 </td>
							</tr>
						</tfoot>
                   	 </table>
                   	 </div>
                  
                  
                   	 
                   </div>
                    
                    </div>
                </div>
         
           
            </div>
            <hr>

<div style="margin-bottom: 150px;">
&nbsp;
</div>
     <!-- FOOTER -->
<nav class="avbar navbar-inverse navbar-fixed-bottom" style="height:50px  ;  background-color:#000  ;">
  <div class="container text-center" style="color:#fff;">
  <p>&nbsp;</p>
   <p ><a href="http://macaronics.net/" style="   color:#fff;">Macaronics.net</a></p>  
    <p>&nbsp;</p><p>&nbsp;</p>
  </div>
</nav>


        <!--/.fluid-container-->
        <script src="../../Bootstrap-Admin/vendors/bootstrap-wysihtml5/lib/js/wysihtml5-0.3.0.js"></script>
        <script src="../../Bootstrap-Admin/vendors/jquery-1.9.1.min.js"></script>
        <script src="../../Bootstrap-Admin/bootstrap/js/bootstrap.min.js"></script>
		<script src="../../Bootstrap-Admin/vendors/bootstrap-wysihtml5/src/bootstrap-wysihtml5.js"></script>
<script src="../../Bootstrap-Admin/vendors/bootstrap-wysihtml5/src/bootstrap-wysihtml5.js"></script>
 
<script type="text/javascript">


$(function() {
    
	// Bootstrap
	$('#bootstrap-editor').wysihtml5();
	
});

</script>
 
  </body>
</html> 
            
 
         

 

 

AdminQnaResaveAction

package net.macaronics.web.admin.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.macaronics.web.admin.controller.dao.AdminQnaDAO;
import net.macaronics.web.controll.action.Action;
import net.macaronics.web.dto.QnaVO;

public class AdminQnaResaveAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String url="MacaronicsServlet?command=admin_qna_list";
		
		String qseq=request.getParameter("qseq").trim();
		String reply=request.getParameter("reply");
		
		
		QnaVO qnaVO=new QnaVO();
		qnaVO.setQseq(Integer.parseInt(qseq));
		qnaVO.setReply(reply);
		
		AdminQnaDAO dao =AdminQnaDAO.getInstance();
		dao.updateQna(qnaVO);
		
		response.sendRedirect(url);
		
	}
	
	

}

 

 

 

 

제작 : macaronics.net - Developer  Jun Ho Choi

소스 :  https://github.com/braverokmc79/jsp_sin

 

${request.getContextPath() } 처리를 안한 부분이 있으므로 

루트 설정( http://macaronics.net/index.php/m01/jsp/view/1352)    및 server.xml  에서 DB 컨넥션 설정은 필수 설정이다.

 

about author

PHRASE

Level 60  라이트

안심하면서 먹는 한 조각 빵이 근심하면서 먹는 잔치보다 낫다. -이솝

댓글 ( 4)

댓글 남기기

작성