Eclipse 환경에서 Java 사용하여 서버 구현
설치
1. Eclipse Workspace
2. JDK 17 (Java Development Kit)
3. Tomcat 설치 (서버 구현)
구현 준비 및 연동 순서
1. Dynamic Web Project 생성
2. main/wepapp/(파일명).jsp 생성
3. 이클립스에 Tomcat 등록
4. Tomcat에 jsp 프로젝트 등록 : Tomcat 우클릭 -> Add and Remove
로컬 서버 환경에서 로그인 / 회원가입 기능 구현
// signIn.html //
<body>
<input type = "text" name = "id">
<input type = "text" name = "pw">
<button onclick = "login()">login</button>
<script>
async function login() {
const id = document.querySelector('[name=id]').value;
const pw = document.querySelector('[name=pw]').value;
const data = await fetch(
`http://localhost:8080/test/signIn.jsp?user-id=${id.value}&user-pw=${pw.value}`
);
const res = await data.text();
console.log(res);
}
login();
</script>
</body>
// signIn.jsp //
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<form action = "" method = "get">
<ul>
<li>
<lable> ID
<input type = "text" name = "user-id"><br>
</li>
<li>
<lable> PW
<input type = "password" name = "user-pw"><br>
</li>
<li>
<lable> PW
<input type = "password" name = "user-pw"><br>
</li>
<li>
<button>Submit</button>
</li>
</ul>
</form>
// signIn_proc.jsp //
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
response.addHeader("Access-Control-Allow-Origin", "*");
%>
<%
// 공식
String id = request.getParameter("user-id");
String pw = request.getParameter("user-pw");
if(id.equals("java") && pw.equals("1234")) {
out.println("Complete.");
} else {
out.println("Check Id and Pw");
}
%>
// signUp.jsp //
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<form action = "signIn_proc.jsp" method = "get">
<ul>
<li>
<lable> ID
<input type = "text" name = "user-id"><br>
</li>
<li>
<lable> PW
<input type = "password" name = "user-pw"><br>
</li>
</ul>
<button>Submit</button>
</form>
// signUp_proc.jsp //
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
// 공식
String id = request.getParameter("user-id");
String pw = request.getParameter("user-pw");
String nm = request.getParameter("user-nm");
out.println(id);
out.println(pw);
out.println(nm);
%>