반응형
realList.jsp의 링크
<td>
<a href="view.do?nno=<%= n.getNno() %>" style="color:<%= n.getTop_yn().equals("Y") ? "red" : "black" %>";>
<%= n.getTitle() %>
</a>
</td>
BoardNoticeViewController.java
package jspservlet.controller;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jspservlet.util.DBConn;
import jspservlet.vo.*;
/**
* Servlet implementation class BoardNoticeViewController
*/
@WebServlet("/board/view.do")
public class BoardNoticeViewController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public BoardNoticeViewController() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String nno = request.getParameter("nno");
Connection conn = null; //DB 연결
PreparedStatement psmt = null; //SQL 등록 및 실행. 보안이 더 좋음!
ResultSet rs = null; //조회 결과를 담음
//try 영역
try{
conn = DBConn.conn();
String sql = "select n.*,uid from notice_board n "
+ " inner join user u "
+ " on n.uno = u.uno "
+ " where nno=?";
psmt = conn.prepareStatement(sql);
psmt.setString(1, nno);
rs = psmt.executeQuery();
if(rs.next()){
NoticeBoardVO board = new NoticeBoardVO();
board.setNno(nno);
board.setTitle(rs.getString("title"));
board.setUid(rs.getString("uid"));
board.setState(rs.getString("state"));
board.setRdate(rs.getString("rdate"));
board.setContent(rs.getString("content"));
request.setAttribute("board", board);
request.getRequestDispatcher("/board/noticeView.jsp").forward(request, response);
}else {
response.sendRedirect(request.getContextPath()+"/index.jsp");
}
}catch(Exception e){
e.printStackTrace();
}finally{
try {
DBConn.close(rs, psmt, conn);
}catch(Exception e) {
e.printStackTrace();
}
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
noticeView.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="jspservlet.vo.*" %>
<%
NoticeBoardVO board = (NoticeBoardVO)request.getAttribute("board");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>공지사항 상세페이지</title>
</head>
<body>
<h2>공지사항 상세페이지</h2><hr>
제목 : <span><%= board.getTitle() %></span><br>
글번호 : <span><%= board.getNno() %></span><br>
작성자 : <span><%= board.getUid() %></span><br>
상태 : <span><%= board.getState() %></span><br>
작성일 : <span><%= board.getRdate() %></span><br>
내용 : <span><%= board.getContent() %></span><br>
</body>
</html>
반응형
'Java' 카테고리의 다른 글
[Servlet] 게시글 삭제 (0) | 2024.10.14 |
---|---|
[Servlet] 게시글 수정 (0) | 2024.10.13 |
[Servlet] 공지 게시글 목록 조회하기 (0) | 2024.10.11 |
[Servlet] 로그인한 회원의 회원 정보 조회 (0) | 2024.10.10 |
[Servlet] 로그인 처리 (0) | 2024.10.09 |