https://tomcat.apache.org/download-90.cgi
-> tar.gz 설치하기
https://earth-95.tistory.com/90
server.xml
69번째줄 수정
port = "80" URIEncoding="UTF-8"
https://velog.io/@nizi123/Mac-OS%EC%97%90-PuTTY-%EC%84%A4%EC%B9%98
https://investechnews.com/mac-putty-install-error/
[putty 설치 오류 해결 참고]
form.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 action="process.jsp" method="get">
난 누구지? 내 이름을 불러봐~!!!<br/>
<input type="text" name="name" />
<button type="submit">확인</button>
</form>
</body>
</html>
process.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>
<% // scriptlet
String name = request.getParameter("name");
out.println("<h1>그래, 난 " + name + ". 포기를 모르는 남자지</h1>");
%>
</body>
</html>
ASP - IIS - MS-SQL
PHP - Apache - MySQL
get 테스트
.
GET /index.jsp HTTP/1.1
Host: localhost:8888
.
GET /basic/process.jsp?name=jungdaeman HTTP/1.1
Host: localhost:8888
post 테스트
.
POST /basic/process.jsp HTTP/1.1
Host: localhost:8888
Content-type: application/x-www-form-urlencoded
User-agent:Mozilla/5.0
Content-Length: 15
.
name=jungdaeman
-> get 방식
<session-config>
<session-timeout>30</session-timeout>
</session-config>
-> 세션을 30분동안 유지
https://www.postman.com/downloads/
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_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>cjyweb01</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>helloServlet2</servlet-name>
<servlet-class>basic.HelloServlet2</servlet-class>
<load-on-startup>20</load-on-startup>
<!-- <init-param>
<param-name>load-on-startup</param-name>
<param-value>10</param-value>
</init-param> -->
</servlet>
<servlet-mapping>
<servlet-name>helloServlet2</servlet-name>
<url-pattern>/helloServlet2</url-pattern>
</servlet-mapping>
</web-app>
form.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 action="process.jsp" method="post">
난 누구지? 내 이름을 불러봐~!!!<br/>
<input type="text" name="name" />
<button type="submit">확인</button>
</form>
</body>
</html>
process.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>
<% // scriptlet
String name = request.getParameter("name");
out.println("<h1>그래, 난 " + name + ". 포기를 모르는 여자지</h1>");
%>
</body>
</html>
HelloServlet.java
package basic;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = "/helloServlet")
public class HelloServlet extends HttpServlet{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("helloServlet service() 수행");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>first servlet</title></head>");
out.println("<body><h1>Hello Servelet~</h1></body>");
out.println("<html>");
out.flush();
}
}
HelloServlet2.java
package basic;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/HelloServelet2")
public class HelloServelet2 extends HttpServlet {
public HelloServelet2() {
System.out.println("HelloServlet2 생성자 수행");
// TODO Auto-generated constructor stub
}
public void init(ServletConfig config) throws ServletException {
System.out.println("HelloServlet2 init() 수행");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("HelloServlet2 doGet() 수행");
// response.getWriter().append("Served at: ").append(request.getContextPath());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("HelloServlet2 doPost() 수행");
// doGet(request, response);
}
protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("HelloServlet2 doPut() 수행");
// doGet(request, response);
}
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("HelloServlet2 doDelete() 수행");
// doGet(request, response);
}
}
Cal.java
package basic;
import java.util.Calendar;
public class Cal {
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH)+1;
System.out.println(year + "," + month);
c.set(year, month-1, 1);
int week = c.get(Calendar.DAY_OF_WEEK);
System.out.println(week);
int endday=c.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println(endday);
System.out.println("일 월 화 수 목 금 토");
System.out.println("----------------");
for(int w=1; w<week; w++) {
System.out.print(" ");
}
for(int d=1, w=week; d<=endday; d++, w++) {
System.out.print( d < 10 ? " " + d + " " : d + " ");
if (w % 7 == 0) System.out.println();
}
}
}
cal.jsp
<%@page import="java.util.Calendar" %>
<%@ 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>
<% // scriptlet
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH)+1;
%>
<table border="1">
<caption><%=year%>, <%=month%></caption>
<tr>
<th>일</th>
<th>월</th>
<th>화</th>
<th>수</th>
<th>목</th>
<th>금</th>
<th>토</th>
</tr>
<tr>
<!-- <td colspan="7">-----------------------</td> -->
</tr>
<tr>
<%
c.set(year, month-1, 1);
int week = c.get(Calendar.DAY_OF_WEEK);
System.out.println(week);
int endday=c.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println(endday);
for(int w=1; w<week; w++) {%>
<td> </td>
<%}
for(int d=1, w=week; d<=endday; d++, w++) {%>
<td><%= d %></td>
<% if (w % 7 == 0)%></tr>
<%}%>
<%for(int w=1; w<3; w++) {%>
<td> </td>
<%}%>
</table>
</body>
</html>
cal.jsp -> 이전달, 다음달 추가버전
<%@page import="java.util.Calendar" %>
<%@ 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>
<% // scriptlet
Calendar c = Calendar.getInstance(); // 이번달
Calendar c2 = Calendar.getInstance(); // 저번달
Calendar c3 = Calendar.getInstance(); // 다음달
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH)+1;
%>
<table border="1">
<caption><%=year%>, <%=month%></caption>
<tr>
<th>일</th>
<th>월</th>
<th>화</th>
<th>수</th>
<th>목</th>
<th>금</th>
<th>토</th>
</tr>
<tr>
<!-- <td colspan="7">-----------------------</td> -->
</tr>
<tr>
<%
c.set(year, month-1, 1);
c2.set(year, month-2,1);
c3.set(year, month, 1);
int week = c.get(Calendar.DAY_OF_WEEK);
int nextMonthWeek = c3.get(Calendar.DAY_OF_WEEK);
System.out.println(week);
int endday=c.getActualMaximum(Calendar.DAY_OF_MONTH);
int lastendday=c2.getActualMaximum(Calendar.DAY_OF_MONTH);
System.out.println(endday);
System.out.println(lastendday);
for(int w=week-1; w > 0; w--) {%>
<td><%= lastendday-w+1%></td>
<%}
for(int d=1, w=week; d<=endday; d++, w++) {%>
<td><%= d %></td>
<% if (w % 7 == 0)%></tr>
<%}%>
<%for(int w=1; w<3; w++) {%>
<td><%= w%></td>
<%}%>
</table>
</body>
</html>