Riucc's Storage
RSS
태그
관리
쓰기
카테고리
  • IT (593)
    • 정리 (0)
    • C# (42)
    • ASP.NET MVC (16)
    • JQuery&Javascript (12)
    • CSS (11)
    • 데이터베이스 (32)
    • Windows Server (6)
    • Active Directory (3)
    • Exchange (9)
    • JAVA (2)
    • JSP (39)
    • JSP 게시판 만들기 (21)
    • JSP 개발 참고 (15)
    • JSP 안드로이드 (4)
    • Servlet (17)
    • Spring (42)
    • HTML (14)
    • NodeJS (46)
    • MongoDB (11)
    • 리눅스 (18)
    • 자료구조 (16)
    • 아이폰 (24)
    • 안드로이드 (68)
    • API 활용하기 (10)
    • 소켓네트워크 (28)
    • 라즈베리파이 (11)
    • AWS클라우드 (10)
    • 빅데이터Hadoop (22)
    • 커널모듈프로그래밍 (8)
    • 기타 (10)
    • 자격증 (26)
Riucc's Storage

[JSP] - 게시물 상세 DB 출력하기

JSP 개발 참고|2018. 5. 5. 21:04
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

○ 게시물 상세 DB 출력하기 


// index.jsp (게시물에서 제목을 클릭하면 상세페이지로...)


<!--  실제 DB에서 최신글 데이터를 뽑아오기 위한 구문 -->

<%

ArrayList<fileDTO> writeList = new ArrayList<fileDTO>();

writeList = new fileDAO().getWriteCreatedList();

for(int i=0; i<writeList.size(); i++){

fileDTO write = writeList.get(i);

%>

<!-- 실제 최신글 데이터를 뽑기 위한 본문 데이터  -->

<div class="row">

<div class="col-lg-9">

<div class="card bg-light mt-3">

<div class="card-header bg-light">

<div class="row">

<div class="col-8 text-left">

<img src="./userProfilePicture/<%= write.getUserPropilePicture() %>" class="img-circle" width="32px" height="27px">&nbsp;<%= write.getUserWriteID() %> &nbsp;<small><%= write.getUserWriteTime() %></small>

</div>

<div class="col-4 text-right"></div>

</div>

</div>


<div class="card-body">

<div class="row">

<div class="col-3">

<img src="./uploadImage/<%= write.getFileRealName() %>" width="150px" height="100px">

</div>

<div class="col-9">

<!-- <h5 class="card-title"><%= write.getTitle() %></h5> -->

<a class="card-title"  href="userWriteDetailView.jsp?userWriteTitle=<%= write.getTitle() %>"><%= write.getTitle() %></a>

<p class="card-text"><%= write.getContent().replaceAll(" ", "&nbsp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\n", "<br>") %></p>


<div class="row">

<div class="col-9 text-left">

금액<span style="color: red;"> <%= write.getUserCoinAmount() %></span> 추천

<span style="color: red;"> <%= write.getUserLikeAmount() %></span> 댓글<span style="color: red;"><%= write.getUserCommentAmount() %></span> 감사<span style="color: red;"> <%= write.getUserReportAmount() %></span>

</div>


<div class="col-3 text-right">

<a onclick="return confirm('보팅 하시겠습니까?')" href="./likeAction.jsp?evaluationID=">추천</a> 

        <a onclick="return confirm('신고 하시겠습니까?')" href="./likeAction.jsp?evaluationID=">신고</a>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</div>


<%

}

%>


 

// userWriteDetailView.jsp (타이틀로 가져와서 db에서 찾아서 출력)


<body>

<%

request.setCharacterEncoding("UTF-8");

%>


<!-- 로그인한 세션 처리 -->

<%

String userSessionID = null;

if (session.getAttribute("userID") != null) {

userSessionID = (String) session.getAttribute("userID");

}

if (userSessionID != null) {

%>

로그인된 사용자 :

<%=userSessionID%>

<%

}

%>


<%

String userWriteTitle = null;


if (request.getParameter("userWriteTitle") != null) {

userWriteTitle = request.getParameter("userWriteTitle");

}


fileDTO file = new fileDAO().getContent(userWriteTitle);

%>


<!-- Nav -->

<nav class="navbar navbar-default bg-primary navbar-fixed-top">

<div class="container-fluid">

<div class="navbar-header">

<a class="navbar-brand text-white" href="index.jsp">사이트 로고</a>

</div>


<ul class="nav justify-content-center">

<li class="nav-item"><a class="nav-link text-white" href="./trendingIndex.jsp">대세글</a></li>

<li class="nav-item"><a class="nav-link text-white" href="./createdIndex.jsp">최신글</a></li>

<li class="nav-item"><a class="nav-link text-white" href="./hotIndex.jsp">인기글</a></li>

</ul>


<ul class="nav justify-content-end">

<!--  유저 로그인 세션이 존재하지 않으면 로그인으로  존재하면 글쓰기로-->

<%

if (userSessionID != null) {

%>

<li class="nav-item"><a class="nav-link text-white" href="./userWrite.jsp">글쓰기</a></li>

<%

} else if (userSessionID == null) {

%>

<li class="nav-item"><a class="nav-link text-white" href="./userLogin.jsp">글쓰기</a></li>

<%

}

%>

<!-- 유저 로그인 세션이 존재하면 로그아웃으로 바뀌게  -->

<%

if (userSessionID == null) {

%>

<li class="nav-item"><a class="nav-link text-white" href="./userLogin.jsp">로그인+회원가입</a></li>

<%

} else if (userSessionID != null) {

%>

<li class="nav-item"><a class="nav-link text-white" href="./userLogoutAction.jsp">로그아웃</a></li>

<%

}

%>

</ul>

</div>

</nav>




<div class="container-fluid">

<div class="row">

<!--  빈공간 3칸 -->

<div class="col-lg-4 mt-4"></div>


<!--  메인 9칸  게시물 출력-->

<div class="col-lg-8 mt-4">


<!-- 컨텐츠 상세 보기 -->


<!-- 컨텐츠 타이틀 출력 -->

<div class="row">

<div class="col-lg-8">

<%=file.getTitle()%>

</div>

</div>


<!-- 유저프로필사진, 유저아이디, 작성시간 출력 -->

<div class="row">

<div class="col-lg-8 mt-2">

<img src="./userProfilePicture/<%=file.getUserPropilePicture()%>" class="img-circle" width="32px" height="27px">&nbsp;<%=file.getUserWriteID()%>

&nbsp;<small><%=file.getUserWriteTime()%></small>

</div>

</div>


<!-- 컨텐츠 사진 출력 -->

<div class="row">

<div class="col-lg-8 mt-3">

<img src="./uploadImage/<%=file.getFileRealName()%>" width="640px" height="360px">

</div>

</div>


<!-- 컨텐츠 본문 출력 -->

<div class="row">

<div class="col-lg-8 mt-3">

<%=file.getContent().replaceAll(" ", "&nbsp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;")

.replaceAll("\n", "<br>")%>

</div>

</div>


<!-- 가격, 추천, 댓글, 감사 출력 -->

<div class="row">

<div class="col-lg-8 mt-3">

금액<span style="color: red;"> <%=file.getUserCoinAmount()%></span> 추천 <span style="color: red;"> <%=file.getUserLikeAmount()%></span> 댓글<span style="color: red;"> <%=file.getUserCommentAmount()%></span> 감사<span style="color: red;"> <%=file.getUserReportAmount()%></span>

</div>

</div>



</div>

</div>

</div>


</body>

</html>


// fileDAO.java (게시물 제목으로 DB 가져오기)


// 하나의 게시물 클릭하면 페이지 이동해서 상세히 보여주게 하는 구문

public fileDTO getContent(String title) {

String SQL = "SELECT * FROM userwriteTest Where userWriteTitle = ?";

Connection conn = null;

PreparedStatement pstmt = null;

ResultSet rs = null;

try {

conn =DatabaseUtil.getConnection();

pstmt = conn.prepareStatement(SQL);

pstmt.setString(1, title);

rs = pstmt.executeQuery();

if(rs.next()) { // 결과가 나왔다면

fileDTO file = new fileDTO();

file.setUserPropilePicture(rs.getString("userPropilePicture"));

file.setUserWriteID(rs.getString("userWriteID"));

// 시간을 오전 오후로 나누어서 표시를 해주자

int chatTime = Integer.parseInt(rs.getString("userWriteTime").substring(11, 13));

String timeType = "오전";

if(Integer.parseInt(rs.getString("userWriteTime").substring(11, 13)) >= 12) {

timeType = "오후";

chatTime -= 12;

}

file.setUserWriteTime(rs.getString("userWriteTime").substring(0, 11) + " " + timeType + " " + chatTime + "시 " + rs.getString("userWriteTime").substring(14, 16) + "분");

file.setFileName(rs.getString("userFileName"));

file.setFileRealName(rs.getString("userFileRealName"));

file.setTitle(rs.getString("userWriteTitle"));

file.setContent(rs.getString("userWriteContent"));

file.setUserCoinAmount(rs.getInt("userCoinAmount"));

file.setUserLikeAmount(rs.getInt("userLikeAmount"));

file.setUserCommentAmount(rs.getInt("userCommentAmount"));

file.setUserReportAmount(rs.getInt("userReportAmount"));

return file;

}

}catch(Exception e) {

e.printStackTrace();

} finally {

try {

if(rs != null) rs.close();

if(pstmt != null) pstmt.close();

} catch(Exception e) {

e.printStackTrace();

}

}

return null; // 글이 존재하지 않는다면 null 반환

}


// fileDTO.java


package file;


public class fileDTO {

String userPropilePicture;

String userWriteID;

String fileName;

String fileRealName;

String title;

String content;

int userCoinAmount;

int userLikeAmount;

int userCommentAmount;

int userReportAmount;

String userWriteTime;

// 생성자 생성

public fileDTO() {}

public fileDTO(String userPropilePicture, String userWriteID, String userWriteTime, String fileName, String fileRealName, String title,

String content, int userCoinAmount, int userLikeAmount, int userCommentAmount, int userReportAmount) {

super();

this.userPropilePicture = userPropilePicture;

this.userWriteID = userWriteID;

this.userWriteTime = userWriteTime;

this.fileName = fileName;

this.fileRealName = fileRealName;

this.title = title;

this.content = content;

this.userCoinAmount = userCoinAmount;

this.userLikeAmount = userLikeAmount;

this.userCommentAmount = userCommentAmount;

this.userReportAmount = userReportAmount;

}


public String getUserWriteTime() {

return userWriteTime;

}


public void setUserWriteTime(String userWriteTime) {

this.userWriteTime = userWriteTime;

}


public String getTitle() {

return title;

}


public String getUserPropilePicture() {

return userPropilePicture;

}


public void setUserPropilePicture(String userPropilePicture) {

this.userPropilePicture = userPropilePicture;

}


public String getUserWriteID() {

return userWriteID;

}


public void setUserWriteID(String userWriteID) {

this.userWriteID = userWriteID;

}


public int getUserCoinAmount() {

return userCoinAmount;

}


public void setUserCoinAmount(int userCoinAmount) {

this.userCoinAmount = userCoinAmount;

}


public int getUserLikeAmount() {

return userLikeAmount;

}


public void setUserLikeAmount(int userLikeAmount) {

this.userLikeAmount = userLikeAmount;

}


public int getUserCommentAmount() {

return userCommentAmount;

}


public void setUserCommentAmount(int userCommentAmount) {

this.userCommentAmount = userCommentAmount;

}


public int getUserReportAmount() {

return userReportAmount;

}


public void setUserReportAmount(int userReportAmount) {

this.userReportAmount = userReportAmount;

}


public void setTitle(String title) {

this.title = title;

}


public String getContent() {

return content;

}


public void setContent(String content) {

this.content = content;

}


public String getFileName() {

return fileName;

}

public void setFileName(String fileName) {

this.fileName = fileName;

}

public String getFileRealName() {

return fileRealName;

}

public void setFileRealName(String fileRealName) {

this.fileRealName = fileRealName;

}

}



저작자표시 (새창열림)

'JSP 개발 참고' 카테고리의 다른 글

[JSP] - 이미지컨텐츠 row 분할하여 출력(nth-child)  (0) 2018.05.14
[JSP] - 다른 테이블에서 작성자 프로필사진 가져오기  (0) 2018.05.06
[JSP] - 게시물 검색 및 검색된 내용의 DB 출력하기  (0) 2018.05.05
[JSP] - 게시물 작성 및 게시물 DB 출력하기  (0) 2018.05.04
[JSP] - 이미지 파일 올렸을 때 미리보기  (0) 2018.05.03

댓글()
카테고리
  • IT (593)
    • 정리 (0)
    • C# (42)
    • ASP.NET MVC (16)
    • JQuery&Javascript (12)
    • CSS (11)
    • 데이터베이스 (32)
    • Windows Server (6)
    • Active Directory (3)
    • Exchange (9)
    • JAVA (2)
    • JSP (39)
    • JSP 게시판 만들기 (21)
    • JSP 개발 참고 (15)
    • JSP 안드로이드 (4)
    • Servlet (17)
    • Spring (42)
    • HTML (14)
    • NodeJS (46)
    • MongoDB (11)
    • 리눅스 (18)
    • 자료구조 (16)
    • 아이폰 (24)
    • 안드로이드 (68)
    • API 활용하기 (10)
    • 소켓네트워크 (28)
    • 라즈베리파이 (11)
    • AWS클라우드 (10)
    • 빅데이터Hadoop (22)
    • 커널모듈프로그래밍 (8)
    • 기타 (10)
    • 자격증 (26)
최근 등록 현황
최근 글
최근 월별 글
최근 댓글
최근 글
최근 월별 글
최근 댓글
최근 글
최근 월별 글
최근 댓글
달력
지난달
2026.2
다음달
일월화수목금토
1234567
891011121314
15161718192021
22232425262728
태그 구름
  • nodejs express
  • 안드로이드 카카오 로그인 연동
  • 정규형
  • nodejs MySQL 연동하기(Connection Pool)
  • 정보처리산업기사 필기 정리
  • 정보처리산업기사 16년 필기
  • 안드로이드 intent
  • 정보처리산업기사 요약
  • HTML
  • 정보처리산업기사 15년 필기
  • 정보처리산업기사 16년
  • 소켓
  • 소켓 프로그래밍
  • 이클립스 디비 연동
  • 정보처리산업기사 필기
  • 정보처리기사 실기 정리
  • 자료구조
  • 커널 모듈 프로그래밍
  • 정보처리산업기사 15년
  • 카카오 로그인
  • 카카오 로그인 연동
  • 정보처리산업기사 정리
  • 정규화
  • 안드로이드 카카오 로그인
  • jsp
  • 리눅스
  • 안드로이드
  • 이클립스 mysql 연동
  • 정보처리산업기사 총정리
  • 데이터베이스
카운터
전체 방문자
오늘
어제
Skin by M1REACT. Designed by M1STORY.TISTORY.COM. Valid XHTML 1.0 and CSS 3. Copyright ⓒ Riucc's Storage. All rights reserved.

티스토리툴바