기록해! 정리해!

Spring - 서블릿 클래스 확인 본문

Spring

Spring - 서블릿 클래스 확인

zsuling 2022. 9. 20. 09:44

교재 42p

[ web.xml ]

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns="http://Java.sun.com/xml/ns/javaee"
 xmlns:web="http://java.sun.com/xml/ns/javaee" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <servlet>
    <description></description>
    <servlet-name>SchoolController</servlet-name>
    <servlet-class>com.springbook.biz.controller.SchoolController</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>SchoolController</servlet-name>
    <url-pattern>/SchoolController.do</url-pattern>
  </servlet-mapping>
  <servlet>
    <description></description>
    <servlet-name>BoardController</servlet-name>
    <servlet-class>com.springbook.biz.controller.BoardController</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>BoardController</servlet-name>
    <url-pattern>/BoardController.to</url-pattern>
  </servlet-mapping>
</web-app>

 

[ index.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>
<div align="center">
<br><br><br>

  <h1>
     <a href=SchoolController.do> Spring 연습1</a> 
  </h1>

  <h1>
     <a href=BoardController.to> Spring 연습2</a> 
  </h1>

</div>
</body>
</html>

package com.springbook.biz.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BoardController
 */
public class BoardController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BoardController() {
        super();
        // TODO Auto-generated constructor stub
        System.out.println("==> BoardController 생성자");
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		// response.getWriter().append("Served at: ").append(request.getContextPath());
		   System.out.println("==> BoardController 의 doGet메소드 ");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}

'Spring' 카테고리의 다른 글

Setter 사용하기 (2) - p 네임스페이스 사용하기  (0) 2022.09.20
Setter 사용하기 (1)  (0) 2022.09.20
ajax + jQuery + 댓글  (0) 2022.09.19
MyBatis  (0) 2022.09.08
Spring - lombok  (0) 2022.08.26
Comments