Annotation을 이용한 서블릿 매핑

decody·2019년 8월 20일

http://localhost:8080/pro06/login.html로 html 페이지 확인
Login 버튼을 클릭후 전송된 데이터 url로 확인 가능하다.

WebContent/login.html 작성

<form name="frmLogin" method="get" action="login" encType="UTF-8">
	<div><label for="idIpt">id:</label><input type="text" name="user_id"></div>
	<div><label for="pwdIpt">pw:</label><input type="password" name="user_pw"></div>
	<input type="submit" value="Login"><input type="reset" value="Reset">
</form> 작성

package sec01.ex01;

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

// annotation: WebServlet
public class LoginServlet  extends HttpServlet {
   public void init() throws ServletException {
      System.out.println("call init()");

   protected void doGet(
		HttpServletRequest req, 
		HttpServletResponse res
   ) throws ServletException, IOException {
		String user_id = req.getParameter("user_id");
		String user_pw = req.getParameter("user_pw"); 
		System.out.println("id: " + user_id);
		System.out.println("pw:" + user_pw);

   public void destroy() {
		System.out.println("call destroy()");

Tomcat의 server.xml에 추가

<Context docBase="pro06" path="/pro06" reloadable="true" source="org.eclipse.jst.jee.server:pro06"/>

위 작성글은 [자바 웹을 다루는 기술]에서 간단히 정리한 것입니다.

Self-Taught Frontend Developer, Designer, and Dad. Want to be an unsung hero in tech. [motto] I design something indefinable in the world.

0개의 댓글