project setting dbconnect, domain, service, dto, dao
This commit is contained in:
@@ -43,6 +43,12 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.21</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.example.jspblog.config;
|
||||
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class CharConfig implements Filter {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
|
||||
request.setCharacterEncoding("utf-8");
|
||||
response.setContentType("text/html; charset=utf-8");
|
||||
|
||||
// String username = request.getParameter("username");
|
||||
// System.out.println("username : " + username);
|
||||
//
|
||||
// PrintWriter out = response.getWriter();
|
||||
// out.println("안녕");
|
||||
// out.flush();
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
23
jspblog/src/main/java/com/example/jspblog/config/DB.java
Normal file
23
jspblog/src/main/java/com/example/jspblog/config/DB.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.example.jspblog.config;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
|
||||
public class DB {
|
||||
|
||||
public static Connection getConnection() {
|
||||
try {
|
||||
Context initContext = new InitialContext();
|
||||
Context envContext = (Context)initContext.lookup("java:/comp/env");
|
||||
DataSource ds = (DataSource)envContext.lookup("jdbc/TestDB");
|
||||
Connection conn = ds.getConnection();
|
||||
return conn;
|
||||
} catch (Exception e) {
|
||||
System.out.println("DB연결 실패");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.example.jspblog.domain.board;
|
||||
|
||||
public class BoardDao {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.example.jspblog.domain.reply;
|
||||
|
||||
public class ReplyDao {
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.example.jspblog.domain.user;
|
||||
|
||||
public class UserDao {
|
||||
|
||||
public void save() { // 회원 가입
|
||||
|
||||
}
|
||||
|
||||
public void update() { // 회원수정
|
||||
|
||||
}
|
||||
|
||||
public void usernameCheck() { // 아이디 중복 체크
|
||||
|
||||
}
|
||||
|
||||
public void findById() { // 회원정보보기
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.example.jspblog.util;
|
||||
|
||||
public class Script {
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.example.jspblog.web;
|
||||
|
||||
import com.example.jspblog.domain.user.dto.JoinReqDto;
|
||||
import com.example.jspblog.domain.user.dto.LoginReqDto;
|
||||
import com.example.jspblog.service.UserService;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
@@ -20,11 +24,30 @@ public class UserController extends HttpServlet {
|
||||
// http://loalhost:8080/jspblog/user?cmd=XXX
|
||||
protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
String cmd = request.getParameter("cmd");
|
||||
UserService userService = new UserService();
|
||||
|
||||
if(cmd.equals("loginForm")) {
|
||||
|
||||
response.sendRedirect("user/loginForm.jsp");
|
||||
} else if (cmd.equals("login")) {
|
||||
|
||||
String username = request.getParameter("username");
|
||||
String password = request.getParameter("password");
|
||||
LoginReqDto dto = new LoginReqDto();
|
||||
dto.setUsername(username);
|
||||
dto.setPassword(password);
|
||||
userService.로그인(dto);
|
||||
} else if (cmd.equals("joinForm")) {
|
||||
response.sendRedirect("user/joinForm.jsp");
|
||||
} else if (cmd.equals("join")) {
|
||||
String username = request.getParameter("username");
|
||||
String password = request.getParameter("password");
|
||||
String email = request.getParameter("email");
|
||||
String address = request.getParameter("address");
|
||||
JoinReqDto dto = new JoinReqDto();
|
||||
dto.setUsername(username);
|
||||
dto.setPassword(password);
|
||||
dto.setEmail(email);
|
||||
dto.setAddress(address);
|
||||
userService.회원가입(dto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
jspblog/src/main/webapp/META-INF/context.xml
Normal file
7
jspblog/src/main/webapp/META-INF/context.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Context>
|
||||
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
|
||||
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
|
||||
username="bloguser" password="blog" driverClassName="com.mysql.cj.jdbc.Driver"
|
||||
url="jdbc:mysql://localhost:3306/blog?serverTimezone=Asia/Seoul"/>
|
||||
</Context>
|
||||
@@ -3,4 +3,22 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
|
||||
<description>MySQL Test App</description>
|
||||
<resource-ref>
|
||||
<description>DB Connection</description>
|
||||
<res-ref-name>jdbc/TestDB</res-ref-name>
|
||||
<res-type>javax.sql.DataSource</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
</resource-ref>
|
||||
|
||||
<filter>
|
||||
<filter-name>charConfig</filter-name>
|
||||
<filter-class>com.example.jspblog.config.CharConfig</filter-class>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>charConfig</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
</web-app>
|
||||
5
jspblog/src/main/webapp/test/dbtest.jsp
Normal file
5
jspblog/src/main/webapp/test/dbtest.jsp
Normal file
@@ -0,0 +1,5 @@
|
||||
<%@ page import="com.example.jspblog.config.DB" %>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<%
|
||||
DB.getConnection();
|
||||
%>
|
||||
10
jspblog/src/main/webapp/user/loginForm.jsp
Normal file
10
jspblog/src/main/webapp/user/loginForm.jsp
Normal file
@@ -0,0 +1,10 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Login Form</h1>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user