๐2022-08-10๐
ํค๋ ๋ถ๋ถ์ด ์๊ณ
response๋ ์ค์ html ์์ค ์ ๋ฌํ๋ ค๋ ๋ด์ฉ์ด ๋ค์ด์๋ค.
์ด์ฐฝ๊ธฐ WWW ๋งต์ ๋ชจ์ต.. ์ฌ๊ธฐ์ ์ ์ ์๋ฏ์ด ์๋ ๋ถํฐ ๊ฑฐ์ฌ๋ฌ ์ฌ๋ผ๊ฐ์๋ฉด,
๋ฏธ๋ฆฌ ๋ง๋ค์ด๋ html ๋ฌธ์๋ฅผ ๋ณด์ฌ์ค๋ค. ์ฒ ์ ํ staticํ ๋ฆฌ์์ค๋ง์ ๋ณด์ฌ์ค๋ค. ๋ฏธ๋ฆฌ ๋ง๋ค์ด๋..
๋ธ๋ผ์ฐ์ ํ๋ฉด์ ์นธ์๋ค๊ฐ ์๊ธฐ ํ๋ฒ์ ์ง์ด ๋ฃ๊ณ ์ ๋ฒํผ์ ๋๋ ์ ๋ ๋ณธ์ธ์ ๋ํ ์๋ฃ
๋ค์ด๋๋ฏนํ ์๋ฃ,,, static ๋ค์ด๋๋ฏน ๊ทธ๋ฆผ์ด ์์ง์ด๋ ์์์ง์ด๋ ๊ทธ๊ฒ ์๋๋ผ staticํ๋ dynamicํ๋,,,
์ฌ์ฉ์ ์์ฒญ์ ๋ฐ๋ผ์ ๊ตฌ๋ถํด์ ๋์ํ๋๊ฒ ํ์ํ๋ค.
์๋ก์ด ์๋ -> ์๋ฐ ๊ธฐ์ค ! ์ฌ์ฉ์๊ฐ ์์ฒญํ๋ ๊ฑฐ์ ๋ฐ๋ผ์ ๋ค๋ฅธ ๋์์ ํด์ฃผ๋ ค๋ฉด ์๋ฐ๋ก ์ง ๋น์ฆ๋์ค ๋ก์ง์ด ํ์ํ๋ค.
servelt ์๋ธ๋ฆฟ
์๋ธ๋ฆฟ์ด๋ Dynamic Web Page๋ฅผ ๋ง๋ค ๋ ์ฌ์ฉ๋๋ ์๋ฐ ๊ธฐ๋ฐ์ ์น ์ ํ๋ฆฌ์ผ์ด์ ํ๋ก๊ทธ๋๋ฐ ๊ธฐ์ ์ ๋๋ค
์น ์ ํ๋ฆฌ์ผ์ด์ ์๋ฒ๋ค. WAS๋ก ์ค์ฌ์ ์ด๋ค. Apache Tomcat ๋ฌด๋ฃ ๋ฒ์ web sphere JEWS ๊ตญ์ฐ ์ ๊ธฐ์
์๋์ฐ start
other - server
doget get๋ฐฉ์์ผ๋ก ํธ์ถํ ๋ default๋ get ๋ฐฉ์
์ธ์ ์ด๋ค ๋ฐฉ์ ๋งคํ
first๋ผ๋ ์ฃผ์๋ก ์ฌ ๋ ์๋ธ๋ ๋งคํ
loginServlet
login.html
server ์ผ์ login.html
LoginServlet.java
package com.gyuone.test01;
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;
/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
String user_id = request.getParameter("user_id"); /* ์
๋ ฅ ์์ ์๋ nameparameter ์๋ฒ๋ attribute๋ฅผ ๋ง์ถ๋ค.*/
String user_pw = request.getParameter("user_pw");
System.out.println("์์ด๋: " + user_id);
System.out.println("ํจ์ค์๋: " + user_pw);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
req.setCharacterEncoding("utf-8");
String user_id = req.getParameter("user_id"); /* ์
๋ ฅ ์์ ์๋ nameparameter ์๋ฒ๋ attribute๋ฅผ ๋ง์ถ๋ค.*/
String user_pw = req.getParameter("user_pw");
resp.setContentType("text/html;charset=utf-8");
PrintWriter out = resp.getWriter();
StringBuffer sb = new StringBuffer();
sb.append("<html>");
sb.append("<body>");
sb.append("์์ด๋");
sb.append(user_id);
sb.append("<br>");
sb.append("๋น๋ฐ๋ฒํธ : ");
sb.append(user_pw);
sb.append("</body>");
sb.append("</html>");
out.print(sb.toString());
}
}
package com.gyuone.test01;
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;
/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
String user_id = request.getParameter("user_id"); /* ์
๋ ฅ ์์ ์๋ nameparameter ์๋ฒ๋ attribute๋ฅผ ๋ง์ถ๋ค.*/
String user_pw = request.getParameter("user_pw");
System.out.println("์์ด๋: " + user_id);
System.out.println("ํจ์ค์๋: " + user_pw);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
req.setCharacterEncoding("utf-8");
String user_id = req.getParameter("user_id"); /* ์
๋ ฅ ์์ ์๋ nameparameter ์๋ฒ๋ attribute๋ฅผ ๋ง์ถ๋ค.*/
String user_pw = req.getParameter("user_pw");
resp.setContentType("text/html;charset=utf-8");
PrintWriter out = resp.getWriter();
StringBuffer sb = new StringBuffer();
sb.append("<html>");
sb.append("<body>");
sb.append("์์ด๋ : ");
sb.append(user_id);
sb.append("<br>");
sb.append("๋น๋ฐ๋ฒํธ : ");
sb.append(user_pw);
sb.append("</body>");
sb.append("</html>");
out.print(sb.toString());
}
}
JSP (Java Server Page)
- ์ด๊ธฐ ์น ํ๋ก๊ทธ๋จ์ ์๋ธ๋ฆฟ์ ์ด์ฉํด์ ๊ตฌํ
- ํ๋ฉด์ ๊ธฐ๋ฅ์ด๋ ๊ตฌ์ฑ์ด ๋ณต์กํด์ง์ ๋ฐ๋ผ ํ๋ก๊ทธ๋๋จธ๊ฐ ์๋ธ๋ฆฟ์ผ๋ก ํ๋ฉด์ ๊ตฌํํ์ง ์๊ณ ์ฃผ๋ก ๋์์ด๋๊ฐ ์ด ์ผ์ ๋ด๋น
- ์๋ธ๋ฆฟ์ ๊ธฐ๋ฅ ์ค ๋ณ๋๋ก ํ๋ฉด ๊ธฐ๋ฅ์ ๋์์ด๋๊ฐ ์์ ํ๊ธฐ ์ฝ๊ฒ ํ๊ธฐ ์ํด JSP๊ฐ ๋ฑ์ฅ
- JSP๋ ๋์์ด๋ ์ ์ฅ์์ ํ๋ฉด์ ์์ํ ๊ธฐ๋ฅ ๊ตฌํ๊ณผ ๊ฐ๋ฐ ํ ํ๋ฉด์ ํธ๋ฆฌํ ์ ์ง๊ด๋ฆฌ๋ฅผ ๋ชฉ์ ์ผ๋ก ๋์
- JSP๋ HTML, CSS์ ์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก JSP ์์๋ค์ ์ฌ์ฉํด ํ๋ฉด์ ๊ตฌํ
E:\source\java\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\ServletTest\org\apache\jsp
hello2.jsp
hello3.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
import="java.util.*"
import="sec02.ex01.*"
pageEncoding="UTF-8"
%>
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-align: center;
}
</style>
<meta charset="UTF-8">
<title>ํ์ ์ ๋ณด ์ถ๋ ฅ์ฐฝ</title>
</head>
<body>
<h1>ํ์ ์ ๋ณด ์ถ๋ ฅ</h1>
<%
request.setCharacterEncoding( "utf-8" );
String _name = request.getParameter("name");
CustomerVO customerVO = new CustomerVO();
customerVO.setCustName(_name);
CustomerDAO dao=new CustomerDAO();
List<CustomerVO> customersList=dao.listCustomers(customerVO);
%>
<table border='1' width='800' align='center'>
<tr align='center' bgcolor='#FFFF66'>
<td>์์ด๋</td>
<td>๋น๋ฐ๋ฒํธ</td>
<td>์ด๋ฆ</td>
<td >์ด๋ฉ์ผ</td>
<td>๊ฐ์
์ผ์</td>
</tr>
<%
for (int i=0; i < customersList.size(); i++){
CustomerVO vo=(CustomerVO) customersList.get(i);
String id=vo.getCustId();
String pwd=vo.getPhone();
String name=vo.getCustName();
String addr=vo.getAddr();
String regDate=vo.getRegDate();
%>
<tr align=center>
<td><%= id %></td>
<td><%= pwd %></td>
<td><%= name %></td>
<td><%= addr %></td>
<td><%=regDate %></td>
</tr>
<%
}
%>
</table>
</body>
</html>
el-ignored
customer1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false" %>
<%
request.setCharacterEncoding("UTF-8");
String custId=request.getParameter("custId");
String pwd=request.getParameter("phone");
String custName= request.getParameter("custName");
String addr= request.getParameter("addr");
String birthDate= request.getParameter("birthDate");
%>
<html>
<head>
<meta charset="UTF-8">
<title>ํ์ ์ ๋ณด ์ถ๋ ฅ์ฐฝ</title>
</head>
<body>
<table border="1" align="center" >
<tr align="center" bgcolor="#99ccff">
<td width="20%"><b>์์ด๋</b></td>
<td width="20%"><b>๋น๋ฐ๋ฒํธ</b></td>
<td width="20%" ><b>์ด๋ฆ</b></td>
<td width="20%"><b>์ฃผ์</b></td>
<td width="20%"><b>์์ผ</b></td>
</tr>
<tr align=center>
<td><%=custId %> </td>
<td><%=pwd%> </td>
<td><%=custName %> </td>
<td><%=addr %> </td>
<td><%=birthDate %> </td>
</tr>
<tr align=center>
<td>${param.custId } </td>
<td>${param.phone } </td>
<td>${param.custName } </td>
<td>${param.addr }</td>
<td>${param.birthDate }</td>
</tr>
</table>
</body>
</html>
customerForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ํ์ ๊ฐ์
์ฐฝ</title>
<body>
<form method="post" action="customer1.jsp">
<h1 style="text-align: center">ํ์ ๊ฐ์
์ฐฝ</h1>
<table align="center">
<tr>
<td width="200"><p align="right">์์ด๋</td>
<td width="400"><input type="text" name="custId"></td>
</tr>
<tr>
<td width="200"><p align="right">๋น๋ฐ๋ฒํธ</td>
<td width="400"><input type="password" name="phone"></td>
</tr>
<tr>
<td width="200"><p align="right">์ด๋ฆ</td>
<td width="400"><p>
<input type="text" name="custName"></td>
</tr>
<tr>
<td width="200"><p align="right">์ฃผ์</td>
<td width="400"><p>
<input type="text" name="addr"></td>
</tr>
<tr>
<td width="200"><p align="right">์์ผ</td>
<td width="400"><p>
<input type="text" name="birthDate"></td>
</tr>
<tr>
<td width="200"><p> </p></td>
<td width="400"><input type="submit" value="๊ฐ์
ํ๊ธฐ"> <input
type="reset" value="๋ค์์
๋ ฅ"></td>
</tr>
</table>
</form>
</body>
</html>
<%
request.setCharacterEncoding("UTF-8");
String custId=request.getParameter("custId");
String pwd=request.getParameter("phone");
String custName= request.getParameter("custName");
String addr= request.getParameter("addr");
String birthDate= request.getParameter("birthDate");
%>
์์๋ ์ด๊ฑฐ๋ฅผ ๊ฐ์ ธ์์ผํ๊ธฐ ๋๋ฌธ์ param์ ๋ง์ด ์ฐ๊ฒ ๋๋ค.
JSTL
JSTL์ ์ ์ ๋ช ์นญ์ ์๋ฐ์๋ฒ ํ์ด์ง ํ์ค ํ๊ทธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(JavaServer Pages Standard Tag Library)์ด๊ณ ์ค์ฌ์ JSTL์ด๋ผ ๋ถ๋ฅธ๋ค.
https://tomcat.apache.org/download-taglibs.cgi
๋ค์ด๋ก๋ ๋ฐ๊ธฐ 4๊ฐ๋ค webapp์ ๋ถ์ฌ๋ฃ๊ธฐ
๊ตญ์ ํ - ๋ค๊ตญ์ด
customer2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
request.setCharacterEncoding("UTF-8");
%>
<c:set var="id" value="hong" scope="page" />
<c:set var="pwd" value="1234" scope="page" />
<c:set var="name" value="${'ํ๊ธธ๋'}" scope="page" />
<c:set var="age" value="${22}" scope="page" />
<c:set var="height" value="${177}" scope="page" />
<html>
<head>
<meta charset=”UTF-8">
<title>ํ์ ์ ๋ณด ์ถ๋ ฅ์ฐฝ</title>
</head>
<body>
<table align="center" border=1 >
<tr align="center" bgcolor="lightgreen" >
<td width="7%" ><b>์์ด๋</b></td>
<td width="7%" ><b>๋น๋ฐ๋ฒํธ</b></td>
<td width="7%" ><b>์ด๋ฆ</b></td>
<td width="7%"><b>๋์ด</b></td>
<td width="7%" ><b>ํค</b></td>
</tr>
<tr align="center">
<td>${id}</td>
<td>${pwd}</td>
<td>${name}</td>
<td>${age}</td>
<td>${height}</td>
</tr>
</table>
</body>
</html>
customer3.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
import="java.util.*" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
List<String> dataList=new ArrayList<String>();
dataList.add("hello");
dataList.add("world");
dataList.add("์๋
ํ์ธ์!!");
%>
<c:set var="list" value="<%=dataList %>" />
<html>
<head>
<meta charset=”UTF-8">
<title>๋ฐ๋ณต๋ฌธ ์ค์ต</title>
</head>
<body>
<c:forEach var="i" begin="1" end="10" step="1" varStatus="loop">
i= ${i} ๋ฐ๋ณตํ์: ${loop.count} <br>
</c:forEach>
<br>
<c:forEach var="i" begin="1" end="10" step="2" >
5 * ${i} = ${5*i}<br>
</c:forEach>
<br>
<c:forEach var="data" items="${list}" >
${data } <br>
</c:forEach>
<br>
<c:set var="fruits" value="์ฌ๊ณผ, ํ์ธ์ ํ, ๋ฐ๋๋, ๋ง๊ณ , ๊ทค" />
<c:forTokens var="token" items="${fruits}" delims="," >
${token} <br>
</c:forTokens>
</body>
</html>
MVC Model View Controller
Django์์๋ MVT ํจํด..
'IT > WEB' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[38์ผ์ฐจ] AOP/ aop concert project (0) | 2022.08.12 |
---|---|
[37์ผ์ฐจ] AutoDi (0) | 2022.08.11 |
[37์ผ์ฐจ] dISample project (0) | 2022.08.11 |
[37์ผ์ฐจ] Spring Bean (0) | 2022.08.11 |
[36์ผ์ฐจ] ์คํ๋ง (0) | 2022.08.10 |
๋๊ธ