๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐ŸŒ  ์ž๋ฐ” ์„œ๋ฒ„ ํŽ˜์ด์ง€ JSP/๐ŸŒŒ ์›น \ ์„œ๋ธ”๋ฆฟ Web , Servlet

Web - Servlet ์‹ค์Šต

by Meteora_ 2021. 3. 14.
728x90

index (client)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<!-- 
server + applet = Servlet

client 					server			DB
		----- > Servar       container
		request์š”์ฒญ
		http             
							web.xml
	    < ------
	    responce์‘๋‹ต			๋™์ ๋ฐฉ์‹(GET POST) 
 -->
 
 <h1>servlet ๊ธฐ๋ณธ</h1>
 
 <form action="location" method = "get">
 	<input type = "submit" value = "GET๋ฐฉ์‹">
 </form>
 
 <form action="location" method = "post">
 	<input type = "submit" value = "Post๋ฐฉ์‹">
 </form>
 
</body>
</html>

xml์— sevlet ์ง€์ •

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  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_3_1.xsd"
  version="3.1">
  
  <servlet>
 		<servlet-name>helloServlet</servlet-name>
 		<servlet-class>sample01.HelloServlet</servlet-class>
 </servlet>
  
 <servlet-mapping>
 		<servlet-name>helloServlet</servlet-name>
 		<url-pattern>/location</url-pattern>
 </servlet-mapping> 
  
  
  </web-app>

 

 

 HelloServlet

 

package sample01;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("HelloServlet doGet");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("HelloServlet doPost");
	}
	
}

๋Œ“๊ธ€