Post Method - 입사지원

김유정·2023년 11월 30일
2

서블릿-퀴즈

목록 보기
7/11
post-custom-banner
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>입사지원</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
</head>
<body>
	<div class="container">
		<h1>입사지원</h1>
		<form method="post" action="/lesson01/quiz09">
			<input type="text" class="form-control col-7  name="name" placeholder="이름을 입력하세요.">	
			
			<div class="mt-3">
				<label for="introduction">자기소개서</label>
				<textarea class="form-control" name="introduction" id="introduction" rows="7"></textarea>
			</div>
  • <div class="mt-3"> 위쪽으로 마진을 3만큼 떨어지게 하겠다.
  • rows="7" textarea의 크기를 아래로 7줄만큼 길어지게 하겠다.
		<button type="submit" class="btn btn-primary w-100 mt-3">지원</button>
		</form>
	</div>

</body>
</html>
  • "btn btn-primary w-100 파란색 예쁜 버튼을 전체 가로사이즈에 꽉 차게 보이도록 만들겠다.
  • class에 w-100 대신에 btn block 을 넣어줘도 된다.
package com.test.lesson01;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/lesson01/quiz09")
public class PostMethodQuiz09 extends HttpServlet {
	
	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
  • post방식이니까 반드시 doPost, get으로 할시 405 에러가 뜬다.
		
		// 응답 헤더 - content type
		response.setContentType("text/html");
		
		// request param
		String name = request.getParameter("name");
		String introduction = request.getParameter("introduction");
		
		// 응답값 뿌리기
		PrintWriter out = response.getWriter();
		out.print("<html><head><title>입사지원서</title></head><body>");
		out.print("<b>" + name + "</b>님 지원이 완료되었습니다.");
		out.print("<h3>지원 내용</h3>");
		out.print(introduction);
		out.print("</body></html>");
		
	}
}

틀렸던 이유: <h3>내용</h3>입력할 때 >를 마저 적지않았다.

profile
열심히 하자
post-custom-banner

0개의 댓글