oneline 게시판 작성, 삭제 - soonbeankim/web1 GitHub Wiki

메인

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>one line 게시판</title>
</head>
<body>
<h3>one line 게시판</h3>


<%

String id = request.getParameter("serial");

String url_mysql = "jdbc:mysql://192.168.0.115/jsplec?serverTimezone=UTC&characterEncoding=utf8&useSSL=false";
String id_mysql = "root";
String pw_mysql = "qwer1234";

PreparedStatement ps = null;
	int cnt=0;
try{
	Class.forName("com.mysql.cj.jdbc.Driver");
	Connection conn_mysql = DriverManager.getConnection(url_mysql, id_mysql, pw_mysql);
	Statement stmt_mysql =conn_mysql.createStatement();
	
	
	String A = "select no, name, title, date from OneLine";
	ResultSet rs = stmt_mysql.executeQuery(A);
	//WhereDefault -얘는 가져오는거!
	%>
<table border="1">	
<tr><th>번호</th><th>이름</th><th>제목</th><th>날짜</th><th>삭제</th></tr>


	<%
	while(rs.next()){
//불러오기화면
%>
<tr><td><%=rs.getString(1) %></td><td><%=rs.getString(2) %></td><td><%=rs.getString(3) %>
</td><td><%=rs.getString(4) %></td><td> 
<a href="oneline_02.jsp?no=<%=rs.getString(1) %>" onclick="return confirm('삭제하시겠습니까?')"> 삭제</a></td></tr>

<%
cnt++;
		
	}
	%>
	
</table>
	<% 
	conn_mysql.close();
	
}catch(Exception e){
	e.printStackTrace();
}


%>
<br>
총 게시글 <%=cnt %> 건 입니다.

<form action="oneline_03.jsp">

<input type="submit" value="글작성">
</form>


</body>
</html>

삭제

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%@ page import="java.sql.*" %>


    
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>삭제</title>
</head>
<body>


<%
request.setCharacterEncoding("utf-8");
	
	int no = Integer.parseInt(request.getParameter("no"));
	
	String url_mysql = "jdbc:mysql://192.168.0.115/jsplec?serverTimezone=UTC&characterEncoding=utf8&useSSL=false";
	String id_mysql = "root";
	String pw_mysql = "qwer1234";
	
	PreparedStatement ps = null;
	try{
		Class.forName("com.mysql.cj.jdbc.Driver");
		Connection conn_mysql = DriverManager.getConnection(url_mysql, id_mysql, pw_mysql);
		Statement stmt_mysql =conn_mysql.createStatement();
		
		String A = "delete from OneLine where no = ? ";
		
		ps = conn_mysql.prepareStatement(A);
		ps.setInt(1,no); 
		ps.executeUpdate();
		
		conn_mysql.close();
		
	}catch(Exception e){
		e.printStackTrace();
	}
	
	response.sendRedirect("oneline_01.jsp");
	
%>


</body>
</html>

작성

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>게시글 작성</title>
</head>
<body>
<h3>게시글을 작성해주세요:D</h3>
<form action="oneline_04.jsp">

이름: <input type="text" name="name"><br>
제목: <input type="text" name="title"><br>


<input type="submit" value="작성">



</form>



</body>
</html>

작성-입력

<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@ 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>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>


<%
	request.setCharacterEncoding("utf-8"); //한글 안깨지도록!!!

	String name = request.getParameter("name");
	String title = request.getParameter("title");
	

	String url_mysql = "jdbc:mysql://192.168.0.115/jsplec?serverTimezone=UTC&characterEncoding=utf8&useSSL=false";
	String id_mysql = "root";
	String pw_mysql = "qwer1234";
	
	PreparedStatement ps = null;
	try{
		Class.forName("com.mysql.cj.jdbc.Driver");
		Connection conn_mysql = DriverManager.getConnection(url_mysql, id_mysql, pw_mysql);
		Statement stmt_mysql =conn_mysql.createStatement();
		
		
		String A = "insert into OneLine (name,title,date) ";
		String B = "values (?,?,now())";
		
		ps = conn_mysql.prepareStatement(A+B);
		ps.setString(1,name);
		ps.setString(2,title);
		
		
		ps.executeUpdate();
		
		conn_mysql.close();


				
	}catch(Exception e){
			
		e.printStackTrace();
	
		
	}
	

	response.sendRedirect("oneline_01.jsp");
%>




</body>
</html>
⚠️ **GitHub.com Fallback** ⚠️