[Java] ๊ฒ์ํ ๋ง๋ค๊ธฐ
์๋ฐ ๊ต์ก์ ๋ฐ์ผ๋ฉฐ ํผ์ ๋งค์ฐ ์์ฃผ ๋ฒ ๋ฆฌ ๊ฐ๋จํ ๊ฒ์ํ์ ๋ง๋ค์ด ๋ดค๋ค.
DataBase : mariaDB
Back-End : Java, JSTL
Front-End : Jsp
Server : Apach Tomcat 9
๊ตฌํ
indexํ์ด์ง
๋ก๊ทธ์ธ ํ์ด์ง
๋ก๊ทธ์ธ ํ ์ด๋๋ ๊ธ ์ ์ฒด๋ณด๊ธฐ ํ์ด์ง
๊ธ ์์ธ๋ณด๊ธฐ
๊ฒ์ํ๊ธฐ : "์ "๋ก ๊ฒ์
ํฌํจ๋ ๊ฒ๋ ๊ฒ์ํ ์ ์๊ฒ ๋ง๋ค์๋ค.
๊ฒ์ํ๊ธฐ : "์ ๋ชฉ4"๋ก ๊ฒ์
๊ฒ์๋ฌผ ์์ฑํ๊ธฐ
์ ๋ ฅํ๊ณ ๋ฑ๋ก ๋๋ฅด๊ธฐ
๋ฑ๋ก๋ฒํผ์ ๋๋ฅด๋ฉด ์ ์ฒด ๋ชฉ๋ก ํ์ด์ง๋ก ๋์ด๊ฐ๋ค.
๊ฒ์๊ธ์ด ์ ์์ฑ๋ ๊ฑธ ๋ณผ ์ ์๋ค.
๊ตฌ์กฐ
๋์ค์๋ beans๋ beans์๋ค๊ฐ ์์น์์ผฐ๊ณ ,
๋ค๋ฅธ ์ปจํธ๋กค๋ฌ, ์๋น์ค, ์๋ธ๋ ์ ๊ทธ ์์ ํด๋์๋ค ์์น์์ผฐ๋ค.
์ ์ฒด ์์ค
BoardController.java
package board.beans;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* ๊ฒ์ํ ์ปจํธ๋กค๋ฌ
*/
public class BoardController {
/** ๊ฒ์ํ ์๋น์ค */
private MariaBoardService boardService = new MariaBoardService();
/** ํ์ ์๋น์ค */
private MariaUserService userService = new MariaUserService();
/**
* ๊ธ ์์ธ ๋ณด๊ธฐ
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String viewBoardDetail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
long id = Long.valueOf(request.getParameter("id"));
BoardPost resultboardpost = boardService.getBoardPost(id);
request.setAttribute("boardpost", resultboardpost);
return "/WEB-INF/jsp/board/viewBoardDetail.jsp";
}
/**
* ๊ธ ์ ์ฒด ๋ชฉ๋ก
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String viewBoardPosts(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String subject = request.getParameter("subject");
List<BoardPost> boardPostList = boardService.getBoardPostAll(subject);
request.setAttribute("boardPosts", boardPostList);
return "/WEB-INF/jsp/board/viewBoardPosts.jsp";
}
/**
* ์ ๊ฒ์๋ฌผ ์์ฑ
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String viewCreateBoardPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
return "/WEB-INF/jsp/board/viewCreateBoardPost.jsp";
}
/**
* ๋ก๊ทธ์ธ ํ๋ฉด
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String viewLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
return "/WEB-INF/jsp/board/viewLogin.jsp";
}
/**
* ๊ธ ์์ฑ ์ฒ๋ฆฌ
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String createBoardPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String title = request.getParameter("title");
String content = request.getParameter("content");
String id = request.getParameter("creatorId");
System.out.println(id);
BoardPost boardPost = boardService.newBoardPost(title, content, id);
BoardPost postResult = boardService.createBoardPost(boardPost); // db insert
return null;
}
/**
*
* @param request
* @param response
* @return
* @throws ServletException
* @throws IOException
*/
public String login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userName = request.getParameter("userName");
String userPassword = request.getParameter("userPassword");
User loginUser = userService.getUser(userName, userPassword);
if (loginUser != null) {
HttpSession session = request.getSession();
session = request.getSession();
session.setAttribute("user", loginUser);
System.out.println("login User :" + loginUser);
} else {
System.out.println("๋ก๊ทธ์ธ ์ ๋จ");
}
return null;
}
}
BoardPost.java
package board.beans;
import java.sql.Timestamp;
/**
* ๊ฒ์ํ
*/
public class BoardPost {
/** ๊ธ๋ฒํธ */
private long id;
/** ์ ๋ชฉ */
private String subject;
/** ๋ด์ฉ */
private String content;
/** ์ฌ์ฉ์ */
private User creator;
/** ์์ฑ ๋ ์ง */
private Timestamp createDate;
/**
* ์์ฑ์
*/
public BoardPost() {
// Do nothing
}
/**
* ์์ฑ์
*
* @param id
* @param subject
* @param content
* @param creator
* @param createDate
*/
public BoardPost(long id, String subject, String content, User creator, Timestamp createDate) {
super();
this.id = id;
this.subject = subject;
this.content = content;
this.creator = creator;
this.createDate = createDate;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public User getCreator() {
return creator;
}
public void setCreator(User creator) {
this.creator = creator;
}
public Timestamp getCreateDate() {
return createDate;
}
public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
}
@Override
public String toString() {
return "BoardPost [id=" + id + ", subject=" + subject + ", content=" + content + ", creator=" + creator + ", createDate="
+ createDate + "]";
}
}
BoardServlet.java
package board.beans;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
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;
/**
* ๊ฒ์ํ ์๋ธ๋ฆฟ
*/
@WebServlet("/board/BoardServlet/*")
public class BoardServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/** ๊ฒ์ํ ์ปจํธ๋กค๋ฌ */
private BoardController boardController = new BoardController();
/**
* @see HttpServlet#HttpServlet()
*/
public BoardServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* ์๋น์ค
*
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stu
// ํ๊ธ ์ค์
request.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=utf-8");
response.setCharacterEncoding("utf-8");
String pathInfo = request.getPathInfo();
String methodName = pathInfo.substring(1);
HttpSession session = request.getSession(false);
User user = (User) session.getAttribute("user");
System.out.println("48 user:" + user);
try {
Method method = boardController.getClass().getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
String result = (String) method.invoke(boardController, request, response);
System.out.println("result :" + result);
if (result != null && !result.equals("")) {
if ((!result.equals("/login") || !result.equals("/WEB-INF/jsp/board/viewLogin.jsp")) && user == null) {
request.getRequestDispatcher("/WEB-INF/jsp/board/viewLogin.jsp").forward(request, response);
} else {
request.getRequestDispatcher(result).forward(request, response);
}
} else {
response.sendRedirect("viewBoardPosts");
}
} catch (NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
MariaBoardService.java
package board.beans;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
public class MariaBoardService {
/**
* Maria DB ์ฐ๊ฒฐ
*
* @return
*/
private Connection getConnection() {
Connection connection = null;
String jdbcUrl = "jdbc:mariadb://127.0.0.1:3306/mysql"; // ๋ง๋ฆฌ์DB ์ฐ๊ฒฐ URL
String username = "root";
String password = "1234";
try {
Class.forName("org.mariadb.jdbc.Driver"); // ๋ง๋ฆฌ์DB JDBC ๋๋ผ์ด๋ฒ ํด๋์ค
connection = DriverManager.getConnection(jdbcUrl, username, password);
if (connection != null) {
System.out.println("์ฐ๊ฒฐ ์ฑ๊ณต");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
/**
* ๊ฒ์๊ธ ์์ธ ๋ณด๊ธฐ
*
* @param id
* @return
*/
public BoardPost getBoardPost(long id) {
Connection connection = getConnection();
if (connection == null) {
return null;
}
BoardPost boardpost = null;
String sql = "SELECT a.id, a.subject, a.content, a.createDate, b.id AS creatorId, b.name AS creatorName, b.fullName AS creatorFullName "
+ " FROM boardpost a, user2 b " + "WHERE a.id LIKE " + id + " AND a.creatorId=b.id; ";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = connection.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs.next()) {
User creator = new User();
long id2 = rs.getLong(1);
String postSubject = rs.getString(2);
String content = rs.getString(3);
Timestamp dateString = rs.getTimestamp(4);
// creator.setId(resultSet.getString("creatorId"));
creator.setId(rs.getLong(5));
creator.setName(rs.getString(6));
creator.setFullName(rs.getString(7));
boardpost = new BoardPost(id2, postSubject, content, creator, dateString);
} else {
System.out.println("๊ฒ์ํญ๋ชฉ ์์");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (pstmt != null)
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (rs != null)
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return boardpost;
}
/**
* ๊ฒ์๊ธ ์ ์ฒด๋ณด๊ธฐ
*
* @param subject
* @return
*/
public List<BoardPost> getBoardPostAll(String subject) {
List<BoardPost> boardPosts = new ArrayList<BoardPost>();
String query = "";
// subject์ ๊ฐ์ด ์๋ค๋ฉด ๊ฒฐ๊ณผ๊ฐ ๋ณด์ฌ์ฃผ๊ธฐ / ์๋๋ผ๋ฉด ์ ์ฒด ๋ชฉ๋ก ๋ณด์ฌ์ฃผ๊ธฐ
if (subject == null) {
query = "SELECT a.id, a.subject, a.content, a.createDate, b.id AS creatorId, b.name AS creatorName, b.fullName AS creatorFullName "
+ " FROM boardpost a, user2 b " + " WHERE a.creatorId = b.id ";
} else {
query = "SELECT a.id, a.subject, a.content, a.createDate, b.id AS creatorId, b.name AS creatorName, b.fullName AS creatorFullName "
+ " FROM boardpost a, user2 b " + " WHERE a.subject like '%" + subject + "%' and a.creatorId = b.id ";
}
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
connection = getConnection();
statement = connection.prepareStatement(query);
resultSet = statement.executeQuery();
while (resultSet.next()) {
User creator = new User();
long id = resultSet.getLong(1);
String postSubject = resultSet.getString(2);
String content = resultSet.getString(3);
Timestamp dateString = resultSet.getTimestamp(4);
creator.setId(resultSet.getLong(5));
creator.setName(resultSet.getString(6));
creator.setFullName(resultSet.getString(7));
boardPosts.add(new BoardPost(id, postSubject, content, creator, dateString));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (statement != null)
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (resultSet != null)
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return boardPosts;
}
/**
* boardpost ๊ฐ์ฒด ์์ฑ
*
* @param request
* @param user
* @return
*/
public BoardPost newBoardPost(String title, String content, String creatorId) {
BoardPost boardPost = new BoardPost();
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
boardPost.setSubject(title);
boardPost.setContent(content);
boardPost.setCreateDate(timestamp);
boardPost.setCreator(new User(Long.valueOf(creatorId), null, null, null, null, 0, null));
System.out.println(boardPost);
return boardPost;
}
/**
* ๊ฒ์๊ธ ์์ฑํ๊ธฐ
*
* @param boardPost
* @return
*/
public BoardPost createBoardPost(BoardPost boardPost) {
Connection connection = getConnection();
if (connection == null) {
return null;
}
String insertQuery = "INSERT INTO boardpost (subject, content, creatorId, createDate) VALUES(?, ?, ?, ?)";
String selectQuery = "select * from boardpost where id = LAST_INSERT_ID()";
PreparedStatement pstmt = null;
PreparedStatement selectedStatement = null;
ResultSet rs = null;
try {
pstmt = connection.prepareStatement(insertQuery);
pstmt.setString(1, boardPost.getSubject());
pstmt.setString(2, boardPost.getContent());
pstmt.setLong(3, boardPost.getCreator().getId());
pstmt.setTimestamp(4, boardPost.getCreateDate());
int num = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (pstmt != null)
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (selectedStatement != null)
selectedStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (rs != null)
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return boardPost;
}
}
MariaUserService.java
package board.beans;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MariaUserService {
/**
* Maria DB ์ฐ๊ฒฐ
*
* @return
*/
private Connection getConnection() {
Connection connection = null;
String jdbcUrl = "jdbc:mariadb://127.0.0.1:3306/mysql"; // ๋ง๋ฆฌ์DB ์ฐ๊ฒฐ URL
String username = "root";
String password = "1234";
try {
Class.forName("org.mariadb.jdbc.Driver"); // ๋ง๋ฆฌ์DB JDBC ๋๋ผ์ด๋ฒ ํด๋์ค
connection = DriverManager.getConnection(jdbcUrl, username, password);
if (connection != null) {
System.out.println("์ฐ๊ฒฐ ์ฑ๊ณต");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
/**
* ๋ก๊ทธ์ธ ํ๊ธฐ
*
* @param request
* @return
*/
public User getUser(String userName, String userPassword) {
Connection connection = getConnection();
String query = "select * from user2 where name like '" + userName + "'";
User user = new User();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = connection.prepareStatement(query);
rs = pstmt.executeQuery();
if (rs.next()) {
String password = rs.getString(4);
if (userPassword.equals(password)) {
System.out.println("๋น๋ฐ๋ฒํธ ์ผ์น " + password);
user.setId(rs.getInt(1));
user.setName(rs.getString(2));
user.setFullName(rs.getString(3));
user.setPassword(rs.getString(4));
user.setEmail(rs.getString(5));
user.setAge(rs.getInt(6));
user.setCreateDate(rs.getTimestamp(7));
}
} else {
user = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
return user;
}
}
User.java
package board.beans;
import java.sql.Timestamp;
/**
* ์ฌ์ฉ์
*/
public class User {
/** ์ฌ์ฉ์ ๊ณ ์ ID */
private long id;
/** ์์ด ์ด๋ฆ */
private String name;
/** ํ๊ตญ์ด ์ด๋ฆ */
private String fullName;
/** ๋น๋ฐ๋ฒํธ */
private String password;
/** ์ด๋ฉ์ผ */
private String email;
/** ๋์ด */
private int age;
/** ๊ฐ์
๋ ์ง */
private Timestamp createDate;
/**
* ์์ฑ์
*/
public User() {
// Do nothing
}
/**
* ์์ฑ์
*
* @param name
* @param age
*/
public User(String name, int age) {
super();
this.name = name;
this.age = age;
}
/**
* ์์ฑ์
*
* @param id
* @param name
* @param fullName
* @param password
* @param email
* @param age
* @param createDate
*/
public User(long id, String name, String fullName, String password, String email, int age, Timestamp createDate) {
super();
this.id = id;
this.name = name;
this.fullName = fullName;
this.password = password;
this.email = email;
this.age = age;
this.createDate = createDate;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Timestamp getCreateDate() {
return createDate;
}
public void setCreateDate(Timestamp createDate) {
this.createDate = createDate;
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + ", fullName=" + fullName + ", password=" + password + ", email=" + email
+ ", age=" + age + ", createDate=" + createDate + "]";
}
}
viewBoardDetail.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<c:if test="${boardpost ne null }">
<h3>${boardpost.id }์์ธ๋ณด๊ธฐ</h3>
<table>
<tr>
<td>ID</td>
<td>${boardpost.id }</td>
</tr>
<tr>
<td>SUBJECT</td>
<td>${boardpost.subject }</td>
</tr>
<tr>
<td>CONTENT</td>
<td>${boardpost.content }</td>
</tr>
<tr>
<td>NAME</td>
<td>${boardpost.creator.fullName }</td>
</tr>
<tr>
<td>DATE</td>
<td>${boardpost.createDate }</td>
</tr>
</table>
</c:if>
</head>
<body>
</body>
</html>
viewBoardPosts.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="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
table, th, tr, td {
border: 1px solid black;
}
table {
width: 80%;
border-collapse: collapse;
}
</style>
</head>
<body>
${user }
<form name="searchForm" action="viewBoardPosts">
<input type="text" name="subject" /> <input type="button" value="๊ฒ์"
onclick="searchBoardPosts()" />
</form>
<br />
<table>
<tr>
<th>ID</th>
<th>์ ๋ชฉ</th>
<th>๋ด์ฉ</th>
<th>์์ฑ์</th>
<th>์์ฑ์ผ</th>
</tr>
<c:forEach var="item" items="${boardPosts }">
<tr>
<td>${item.id }</td>
<td><a href="viewBoardDetail?id=${item.id }">${item.subject }</a></td>
<td>${item.content }</td>
<td>${item.creator.fullName }</td>
<td>${fn:substring(item.createDate, 0, 10)}</td>
</tr>
</c:forEach>
</table>
<br />
<a href="viewCreateBoardPost">๊ฒ์๋ฌผ ์์ฑ</a>
<script>
function searchBoardPosts() {
document.searchForm.submit();
}
</script>
</body>
</html>
viewCreateBoardPost.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
.f {
margin-top: 10px;
margin-bottom: 10px;
}
input {
width: 200px;
}
textarea {
width: 200px;
}
</style>
</head>
${user }
<form name="mainForm" method="post" action="createBoardPost">
<div class="f">
์ ๋ชฉ <input type="text" name="title" placeholder="์ ๋ชฉ ์
๋ ฅ" />
</div>
<div class="f">
๋ด์ฉ
<textarea name="content"></textarea>
</div>
<c:if test="${user ne null}">
<input type="hidden" name="creatorId" value="${user.id }">
</c:if>
<div class="f">
์ ๋ชฉ <input type="button" value="๋ฑ๋ก" onclick="createBoardPost()">
</div>
</form>
<script>
function createBoardPost() {
let title = document.mainForm.title.value;
let content = document.mainForm.content.value;
if (title == null || title == "") {
alert("์ ๋ชฉ์ ์
๋ ฅํ์ธ์");
} else if (content == null || content == "") {
alert("๋ด์ฉ์ ์
๋ ฅํ์ธ์");
} else {
document.mainForm.submit();
}
}
</script>
</body>
</html>
viewLogin.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form name="mainForm" method="post" action="login">
<div>
userName <input type="text" name="userName" />
</div>
<div>
userPassword <input type="text" name="userPassword" />
</div>
<div>
<input type="button" onclick="login()" value="๋ก๊ทธ์ธ">
</div>
</form>
<script>
function login() {
let id = document.mainForm.userName.value;
let password = document.mainForm.userPassword.value;
if (id == null || id == "") {
alert("userName์ ์
๋ ฅํด์ฃผ์ธ์");
} else if (password == null || password == "") {
alert("userPassword๋ฅผ ์
๋ ฅํด์ฃผ์ธ์");
} else {
document.mainForm.submit();
}
}
</script>
</body>
</html>
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="board/BoardServlet/viewLogin">๋ก๊ทธ์ธ</a>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>123007</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/lib/c.tld</taglib-location>
</taglib>
</jsp-config>
<servlet>
<servlet-name>BoardServlet1</servlet-name>
<servlet-class>board.beans.BoardServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BoardServlet1</servlet-name>
<url-pattern>/servlet/BoardServlet/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MultiplicationServlet</servlet-name>
<servlet-class>multiplication.MultiplicationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MultiplicationServlet</servlet-name>
<url-pattern>/servlet/MultiplicationServlet</url-pattern>
</servlet-mapping>
</web-app>